Variable packages are now the vector of structures, hence each and every element in the vector is a structure. To show one element in the vector, an index into the vector would be identified. For illustration, to refer to the second element:
c ost: 5.9900
To refer to the field, it is essential to refer to the specific structure, and then the field within it. This means that using an index into the vector to refer to the structure, and then the dot operator to refer the field. For illustration:
Hence, there are necessarily three levels to this data structure. The variable packages are at highest level that is a vector of structures. Each of its elements is a separate structure. The fields within these individual structures are at lowest level. The loop below displays each element in the packages vector.
>> for i = 1:length(packages)
To refer to a specific field for all structures, in most of the programming languages it would be essential to loop through all the elements in vector and use the dot operator to refer to the field for each element. Though, this is not the case of MATLAB.