Variable packages, MATLAB in Statistics

Variable packages:

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:

>> packages(2)

ans =

item_no: 456

   c  ost: 5.9900

   price: 49.9900

   code: 'l'

 

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:

>> packages(1).code

ans =

g

 

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)

disp(packages(i))

end

   item_no: 123

cost: 19.9900

price: 39.9500

code: 'g'

   item_no: 456

cost: 5.9900

price: 49.9900

code: 'l'

   item_no: 587

cost: 11.1100

price: 33.3300

code: 'w'

 

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.

Posted Date: 10/20/2012 6:06:17 AM | Location : United States







Related Discussions:- Variable packages, Assignment Help, Ask Question on Variable packages, Get Answer, Expert's Help, Variable packages Discussions

Write discussion on Variable packages
Your posts are moderated
Related Questions
Areacirc function: The areacirc function can be called from the Command Window as shown here, or from a script. Here is a script which will prompt the user for the radius of o

Function Stubs: The other common debugging method, which is used when there is a script main program which calls many functions, is to use the function stubs. A function stub

Nested for Loops: The action of a loop can be any of the valid statement(s). Whenever the action of a loop is the other loop, this is known as nested loop. As an illustrati

Example of customizing plots: As the other illustration of customizing plots, the pieces of a pie chart can be "exploded" from the rest. In this situation, the two vectors are

Variable packages: 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 i

Example of Functions which complete a task: For illustration, the function below just prints the number arguments passed to it in a sentence format: As this function i

Statistics There are numerous statistical analyses which can be executed on data sets. In MATLAB software, the statistical functions are in the data analysis help topic known a

Illustration of Median When the vector is not in sorted order to start with, the median function will still return the right answer (it will sort the vector automatically). For

Index vector: The index vector is then used as the indices for original vector. To get grades vector in ascending order, the indices used would be grades (2), grades (5), and

Advanced File Input and Output: In that section, we saw how to read the values entered by user using the input as well as the output functions disp and fprintf, that shows inf