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
Illustration sorting vectors of structures: This function sorts the structures depend only on the price field. A more common function is shown next, that receives a string whi

Illustration of Sound files: For illustration, the following script generates a subplot which shows the signals from chirp and from train, which is as shown in figure:

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

Illustration of Set operations: For illustration, given the vectors as shown below: >> v1 = 2:6 v1 = 2  3  4  5  6 >> v2 = 1:2:7 v2 = 1  3  5  7

Illustration of initializing the data structure: illustration of initializing the data structure by preallocating is here as shown: >> cyls(3) = struct('code', 'c', 'dimen

Illustration of Preallocating a Vector: Illustration of calling the function: >> myveccumsum([5 9 4]) ans =     5  14  18 At the first time in the loop, outvec wil

Structures: The Structures are data structures which group together values which are logically related in what are known as the fields of structure. The benefit of structures

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

Use of While loop: Here is an illustration of calling the function, passing 5000 for the value of the input argument high. >> factgthigh(5000) ans = 5040 The itera

Example of Plotting from a Function: For illustration, the function can be called as shown below:      >> y = [1:2:9].^3      y =     1  27  125  343  729