Index Substructures and Fields
As in MATLAB®, you index substructures and fields structures in MATLAB Function blocks by using dot notation. However, for code generation from MATLAB, you must reference field values individually (see Structure Definition for Code Generation).
For example, in the Read and Write Buses with a MATLAB Function Block example, the MATLAB function uses dot notation to index fields and substructures:
function [outbus, outbus1] = fcn(inbus) %#codegen substruct.a1 = inbus.ele3.a1; substruct.a2 = int8([1 2;3 4]); mystruct = struct('ele1',20.5,'ele2',single(100), 'ele3',substruct); outbus = mystruct; outbus.ele3.a2 = 2*(substruct.a2); outbus1 = inbus.ele3;
The following table shows how the code generation software resolves symbols in dot notation for indexing elements of the structures in this example:
Dot Notation | Symbol Resolution |
---|---|
substruct.a1 | Field a1 of local structure
substruct |
inbus.ele3.a1 | Value of field a1 of field ele3 , a
substructure of structure inputinbus |
inbus.ele3.a2(1,1) | Value in row 1, column 1 of field a2 of field
ele3 , a substructure of structure input
inbus |