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
Creating a cell array: The other method of creating a cell array is easy to assign values to particular array elements and build it up element by element. Though, as explained

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


Write a program to examine exponential function: We will write a program to examine the value of e and the exponential function. It will be a menu-driven. The menu options wil

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


Vector operations: As vectors are special cases of matrices, the matrix operations elaborated (addition, subtraction, multiplication, scalar multiplication, transpose) work on

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

Executing a program: Running the program would be completed by typing the name of the script; this would call the other functions: >> calcandprintarea Whenever prompt

Function used in binary search: The function below implements this binary search algorithm. It receives two arguments: the sorted vector and a key (on the other hand, the func