Technique to creating this structure, MATLAB in Engineering

Technique to creating this structure:

An alternative technique of creating this structure, that is not as efficient, includes using the dot operator to refer to fields in the structure. The name of structure variable is followed by dot, or a period, and then name of the field within that structure. The Assignment statements can be used to assign values to the fields.

>> package.item_no = 123;

>> package.cost = 19.99;

>> package.price = 39.95;

>> package.code = 'g';

 

By using the dot operator in the first assignment statement, the structure variable is generated with the field item_no. The later three assignment statements add more fields to the structure variable.

Adding a field to the structure later is accomplished as shown former, by using an assignment statement.

The whole structure variable can be assigned to the other. This would make sense, for illustration, if the two structures had some values in common. Here, for illustration, the values from one structure are copied into the other and then two fields are selectively changed.

 

>> newpack = package;

>> newpack.item_no = 111;

>> newpack.price = 34.95

newpack =

item_no: 111

cost: 19.9900

price: 34.9500

code: 'g'

 

Posted Date: 10/20/2012 5:56:24 AM | Location : United States







Related Discussions:- Technique to creating this structure, Assignment Help, Ask Question on Technique to creating this structure, Get Answer, Expert's Help, Technique to creating this structure Discussions

Write discussion on Technique to creating this structure
Your posts are moderated
Related Questions
str2num function - String: The function str2num does the opposite; it takes the string in which a number is stored and converts it to the type double: >> num = str2num('123.

Uses of Function handles: The Function handles can also be generated for functions other than anonymous functions, both built-in & user-defined functions. For illustration, th

Passing Structures to Functions: The whole structure can be passed to a function, or separate fields can be passed. For illustration, here are the two distinct versions of a f

Example of Menu driven modular program: As an illustration of such a menu-driven program, we will write a program to discover the constant e. The constant e, known as the n

Forward substitution: The Forward substitution (done methodically by first getting a 0 in the a 21 place, and then a 31 , and lastly a 32 ): For the Gauss technique,

Patch function - graphics objects: The patch function is used to generate a patch graphics object, which is made from 2-dimensional polygons. The patch is defined by its verti

Example of file ploting data: As the other example, a data file called 'compsales.dat' stores the sales figures (in millions) for divisions in a company. Each line in the f

Related Structure Functions: There are many functions which can be used with structures in a MATLAB. The function isstruct will return 1 for logical true when the variable arg


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