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
Individual structure variable: The individual structure variable for one software package may look like this: The name of the structure variable is a package; it has f

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

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

Implementation of binary search: The binary search can be implemented as a recursive function. The recursive function below also implements this binary search algorithm. It re


Illustration of gauss-jordan elimination: An illustration of interchanging rows would be r1 ¬→ r3, that would results: Now, beginning with this matrix, an illustration of sc

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

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

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

Storing Strings in Cell Arrays: The one good application of a cell array is to store strings of various lengths. As cell arrays can store various types of values in the elemen