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
Displaying the cell arrays: There are several techniques of displaying the cell arrays. The celldisp function shows all elements of the cell array:   >> celldisp(cellro

Illustration of Subfunctions: This is an illustration of running this program: >> rectarea Please enter the length: 6 Please enter the width: 3 For a rectan

Function iscellstr - string function: The function iscellstr will return the logical true when a cell array is a cell array of all the strings, or logical false if not. >>

Finding a sting - function strfind: The function strfind does necessarily similar thing, except that the order of the arguments does make dissimilarity. The common form is str

Finding products by for loop: an illustration, when 5 is passed to be the value of the input argument n, the function will compute and return 1 + 2 + 3 + 4 + 5, or 15: >> s

Illustration of if - else statement: The one application of an if-else statement is to check for errors in the inputs to a script. For illustration, a former script prompted t

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

Illustration of gauss-jordan: Here's an illustration of performing such substitutions by using MATLAB >> a = [1 3 0; 2 1 3; 4 2 3] a = 1 3 0 2 1 3 4 2

Use polyval to evaluate the derivative at xder. This will be the % slope of the tangent line, "a" (general form of a line: y = ax + b). % 4. Calculate the intercept, b, of t

num2str function: The num2str function, that converts real numbers, can be called in many ways. If only the real number is passed to the num2str function, it will generate a s