Index Substructures and Fields
Use these guidelines when indexing substructures and fields for code generation:
For example, the following MATLAB® code uses dot notation to index fields and substructures:
... substruct1.a1 = 15.2; substruct1.a2 = int8([1 2;3 4]); mystruct = struct('ele1',20.5,'ele2',single(100), 'ele3',substruct1); substruct2 = mystruct; substruct2.ele3.a2 = 2*(substruct1.a2); ...
The generated code indexes elements of the structures in this example by resolving symbols as follows:
|Dot Notation||Symbol Resolution|
|Value of field |
|Value in row 1, column 1 of field |
To reference the value of a field in a structure array, you must index into the array to the structure of interest and then reference that structure's field individually using dot notation, as in this example:
... y = X(1).a % Extracts the value of field a % of the first structure in array X ...
To reference all the values
of a particular field for each structure in an array, use this notation
for loop, as in this example:
... s.a = 0; s.b = 0; X = repmat(s,1,5); for i = 1:5 X(i).a = i; X(i).b = i+1; end
You cannot reference fields in a structure by using dynamic names, which express the field as a variable expression that MATLAB evaluates at run time (see Generate Field Names from Variables).
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.