Skip to Main Content Skip to Search
Product Documentation

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];

As an exception to zero-based indexing, scalar expansion is available. 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.

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS