Products & Services Solutions Academia Support User Community Company

Learn more about Stateflow   

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 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.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

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