Technique to create nested structures, MATLAB in Engineering

Technique to create Nested structures:

This technique is the most proficient. Though, the other technique is to build the nested structure one field at a time. As this is a nested structure with one structure inside of the other, the dot operator should be used twice here to get to the real x- and y-coordinates.

 

>> lineseg.endpoint1.x = 2;

>> lineseg.endpoint1.y = 4;

>> lineseg.endpoint2.x = 1;

>> lineseg.endpoint2.y = 6;

 

The nested structure has been once created; we can refer to various parts of the variable lineseg. Just typing the name of the variable represents only that it is a structure having two fields, endpoint1 and endpoint2, each of which is a structure.

>> lineseg

lineseg =

  endpoint1: [1x1 struct]

  endpoint2: [1x1 struct]

 

Typing the name of the nested structures will show the field names and the values within that structure:

>> lineseg.endpoint1

ans =

  x: 2

  y: 4

 

By using the dot operator twice will refer to a separate coordinate, for illustration,

>> lineseg.endpoint1.x

ans =

    2

Posted Date: 10/20/2012 6:08:27 AM | Location : United States







Related Discussions:- Technique to create nested structures, Assignment Help, Ask Question on Technique to create nested structures, Get Answer, Expert's Help, Technique to create nested structures Discussions

Write discussion on Technique to create nested structures
Your posts are moderated
Related Questions
Modular programs: In a modular program, the answer is broken down into modules, and each is executed as a function. The script is usually known as the main program. In orde

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

Program of passing arguments to functions: This was an illustration of a function which did not receive any input arguments nor did it return any output arguments; it easily a

Cross Product: The cross or outer product a × b of two vectors a and b is defined only whenever both a and b are the vectors in three-dimensional space, that means that they b

Algorithm for expfn function: The algorithm for expfn function is as shown:  receives the value of x as the input argument.  Prints the value of exp(x).  assigns a

Replacing a string - function strrep: The function strrep finds all the occurrences of a substring within the string, and substitutes them with a new substring. The order of a

Matrix solutions to systems of the linear algebraic equations: The linear algebraic equation is an equation of the form a 1 x 1 + a 2 x 2 + a 3 x 3    .  .  .  .  a n x n

. Generate the following signal, x(n)=1+cos((25*pi*n)/100),0 Compute the DTFT of x[n] for w=0:0.01:2*pi Plot the Real part, imaginary part, the amplitude and phas

Example Exit modular program: In the illustration below, the user  Chose the Limit; -   Whenever prompted for n, entered the two invalid values before finally ente

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