Using Arrays in Actions

Array Notation

A Stateflow® action uses C style syntax and zero-based indexing by default to access array elements. This differs from MATLAB® notation, which uses 1-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]. Here are other examples of how to access and assign values to array elements in Stateflow actions:

local_array[1][8][0] = 10;

local_array[i][j][k] = 77;

var = local_array[i][j][k];

As an exception to this style, 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;

Arrays and Custom Code

Stateflow action language provides the same syntax for Stateflow arrays and custom code arrays.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS