Illustration of initializing the data structure, MATLAB in Engineering

Illustration of initializing the data structure:

illustration of initializing the data structure by preallocating is here as shown:

>> cyls(3) = struct('code', 'c', 'dimensions',.  .  .

  struct('rad', 3, 'height', 6), 'weight', 9);

>> cyls(1) = struct('code', 'x', 'dimensions',.  .  .

  struct('rad', 3, 'height', 6), 'weight', 7);

>> cyls(2) = struct('code', 'a', 'dimensions',.  .  .

  struct('rad', 4, 'height', 2), 'weight', 5);

Alternatively, it could be initialized by using the dot operator:

>> cyls(3).code = 'c';

>> cyls(3).dimensions.rad = 3;

>> cyls(3).dimensions.height = 6;

>> cyls(3).weight = 9;

>> cyls(1).code = 'x';

>> cyls(1).dimensions.rad = 3;

>> cyls(1).dimensions.height = 6;

>> cyls(1).weight = 7;

>> cyls(2).code = 'a';

>> cyls(2).dimensions.rad = 4;

>> cyls(2).dimensions.height = 2;

>> cyls(2).weight = 5;

Posted Date: 10/20/2012 6:12:21 AM | Location : United States







Related Discussions:- Illustration of initializing the data structure, Assignment Help, Ask Question on Illustration of initializing the data structure, Get Answer, Expert's Help, Illustration of initializing the data structure Discussions

Write discussion on Illustration of initializing the data structure
Your posts are moderated
Related Questions
Plotting from a Function: The following function creates a Figure Window as shown in figure, which shows various types of plots for similar y vector. The vector is passed as a

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

Expanding a function: The expand function will multiply out terms, and factor will do the opposite: >> expand((x+2)*(x-1)) ans = x^2 x-2 >> factor(ans)

Example to change the line width from the default: For illustration, to change the line width from the default of 0.5 to 1.5: >> set(hl,'LineWidth',1.5) As long as the

Patch function - graphics objects: The patch function is used to generate a patch graphics object, which is made from 2-dimensional polygons. The patch is defined by its verti

Function rmfield - structure: The function rmfield eliminates a field from the structure. It returns a new structure with field eliminated, but does not modify the original st

Anonymous Functions: The anonymous function is a very easy, one-line function. The benefit of an anonymous function is that it does not have to be stored in an M-file. This ca

Preallocating a Vector: There are necessarily two programming techniques that can be used to simulate the cumsum function. One technique is to begin with an empty vector and c

function numden: The function numden will return individually the numerator & denominator of a symbolic expression: >> sym(1/3 + 1/2) ans = 5/6 >> [n, d] =

Program to Counting in a while loop: The script initializes variable counter to 0. Then, in the while loop action, each and every time the user successfully enter a number, th