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 =


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
Interpolation and extrapolation: In most cases, it is desired to estimate values other than at the sampled data points. For illustration, we may want to estimate what the temp

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 Passing arguments to functions: Here is an illustration of calling this function: >> printrand() The random # is 0.94 As nothing is passed to

Use of Nested if-else statements: By using the nested if-else to select from among the three possibilities, not all the conditions should be tested. In this situation, if x is

Data structures: The Data structures are variables which store more than one value. In order to made sense to store more than one value in a variable, the values must in some

Finding a sting - function findstr: The function findstr receives two strings as input arguments. It finds all the occurrences of shorter string contained by the longer, and r

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] =

Print from the structure: To print from the structure, a disp function will show either the whole structure or a field. >> disp(package) item_no: 123 cost: 19.99

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