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 =



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)



   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
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

Functions which return Values versus printing: Also, the function which computes and returns values (throughout the output arguments) does not generally print them; that is le

Operation on file: We concentrate first on the fgetl function that reads strings from the file one line at a time. The fgetl functions afford more control over how the data is

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

Determine sequence weights for the sequences ACTA, ACTT, CGTT, and AGAT in problem 1 by using Thompson, Higgins, and Gibson method a) compute pairwise distances between sequences

Representing Logical true and False: It has been stated that expressions which are theoretically true really have the integer value of 1, and expressions which are theoretical

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

Functions which complete a task without returning Values: Most of the functions do not compute values, but instead of accomplish a task like printing formatted output. As thes

Sorting Strings: For the matrix of strings, the sort function works exactly as formerly for numbers. For illustration, >> words = char('Hi', 'Hello', 'Howdy', 'Goodbye', '

Input in a While Loop: The script below repeats the procedure of prompting a user, the reading in a positive number, and echo-printing it, as long as the user properly enters