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
Example of Functions which return values: Calling this function prints the circumference, since there is no way to store the value, hence, it can be used in following computat

function sortrows - sorting strings: The function sortrows sorts each and every row as a block, or group, and it also will work on numbers. Here in this illustration the rows

Need of a nested loop: How would we sum each individual column, rather than getting an overall sum? Answer: The programming technique would need a nested loop in whi

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

Properties of the text box - graphics objects: By using get will show properties of the text box, the illustration is as shown below: >> get(thand)   BackgroundColor

Location of a rectangle - graphics objects: The location of a rectangle is [x y w h], where x and y are the coordinates of the lower left point, here w is the width, and h is

Median The median is defined only for a data set which has been sorted first, that means that the values are in order. The median of a sorted set of data values (n) is defined

Illustration of Nested loops: Running the script shows the output: >> printstars ***** ***** ***** The variable rows identifies the number of rows to print, and

Vectorizing: In most of the cases in MATLAB, loops are not essential. As MATLAB is written specifically to work with the vectors and matrices, most operations can be completed

Program of Persistent variables: The program below elaborates this. The script calls a function func1 that initializes a variable count to 0, then increment it, and print the