Initializing the data structure - function, MATLAB in Engineering

Initializing the data structure - Function:

Function is shown as:

 

>> printcylvols(cyls)

Cylinder x has a volume of 169.6

Cylinder a has a volume of 100.5

Cylinder c has a volume of 169.6

 

Note that in the whole data structure, cyls, is passed into the function. The function loops through each and every element, where each is a structure. It prints the code field for each, that is given by the cyls(i) code. In order to compute the volume of cylinder, the radius and height are only required, so instead of passing the whole structure to the subfunction cylvol (that would be cyls(i)), only the dimensions field is passed. The function then receives the dimensions structure as an input argument, and uses a dot operator to refer  the rad and height fields within it.

 

Posted Date: 10/20/2012 6:14:41 AM | Location : United States







Related Discussions:- Initializing the data structure - function, Assignment Help, Ask Question on Initializing the data structure - function, Get Answer, Expert's Help, Initializing the data structure - function Discussions

Write discussion on Initializing the data structure - function
Your posts are moderated
Related Questions
Help command: The help command is used with the script rectarea, the function readlenwid, and the major function printrectarea. To see the first comment in the subfunction, as

Sort algorithm for Sorting vectors of structures: Note that only the price field is compared in the sort algorithm, but the whole structure is replaced. That is therefore each

Passing arguments to functions: In all these functions examples faraway, at least one of the arguments was passed in the function call to be the value(s) of the equivalent inp

Intersect function and setdiff function: The intersect function rather than returns all the values which can be found in both of the input argument vectors. >> intersect(v

Subfunctions: Though, it is possible to have more than one function in a given M-file. For illustration, if one function calls the other, the first function would be the prima

Binary Search: The binary search supposes that the vector has been sorted first. The algorithm is just similar to the way it works whenever looking for a name in a phone direc

Referring to and Showing Cell Array Elements and Attributes: Just as with the other vectors, we can refer to individual elements of the cell arrays. The only difference is tha

Use of Nested if-else statements: By using the nested if-else to select from among the three possibilities, not all the conditions should be tested. In this situation, if x is

Creating Cell arrays: There are many ways to create cell arrays. For illustration, we will create a cell array in which one element will store an integer, one element store ch

Illustration of Gauss elimination: For illustration, for a 2 × 2 system, an augmented matrix be: Then, the EROs is applied to obtain the augmented matrix into an upper