Using Arrays in Actions
Array Notation
A Stateflow action uses C style syntax and zero-based
indexing by default to access array elements. This syntax differs
from MATLAB notation, which uses one-based indexing. For example,
suppose you define a Stateflow input A of
size [3 4]. To access the element in the first
row, second column, use the expression A[0][1].
Other examples of zero-based indexing in Stateflow actions include:
local_array[1][8][0] = 10;
local_array[i][j][k] = 77;
var = local_array[i][j][k];
Note
Use the same notation for accessing arrays in Stateflow charts,
from Simulink models, and from custom code. |
As an exception to zero-based indexing, scalar
expansion is available within the action language. This
statement assigns a value of 10 to all the elements of the array local_array.
local_array = 10;
Scalar expansion is available for performing general operations.
This statement is valid if the arrays array_1, array_2,
and array_3 have the same value for the Sizes property.
array_1 = (3*array_2) + array_3;
Back to Top
Arrays and Custom Code
Stateflow action language provides the same syntax for Stateflow arrays
and custom code arrays.
Note
Any array variable that is referred to in a Stateflow chart
but is not defined in the Stateflow hierarchy is identified as
a custom code variable. |
Back to Top
 | Using Data and Event Arguments in Actions | | Broadcasting Events in Actions |  |
Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
Get this Simulink Kit