Skip to Main Content Skip to Search
Product Documentation

How to Define Vectors and Matrices

Defining a Vector

Define a vector in a Stateflow chart as follows:

  1. Add data to your chart as described in Adding Data.

  2. In the General pane of the Data properties dialog box, enter the dimensions of the vector in the Size field.

    For example, enter [4 1] to specify a 4-by-1 vector.

  3. Specify the name, base type, and other properties for the new data.

  4. Set initial values for the vector.

    • If initial values of all elements are the same, enter a real number in the Initial value field. This value applies to all elements of a vector of any size.

    • If initial values differ, enter real numbers in the Initial value field. For example, you can enter:

      [1; 3; 5; 7]

      Tip   If you want to initialize all elements of a vector to 0, do nothing. When no values are explicitly defined, all elements initialize to 0.

  5. Click Apply.

Defining a Matrix

Define a matrix in a Stateflow chart as follows:

  1. Add data to your chart as described in Adding Data.

  2. In the General pane of the Data properties dialog box, enter the dimensions of the matrix in the Size field.

    For example, enter [3 3] to specify a 3-by-3 matrix.

  3. Specify the name, base type, and other properties for the new data.

  4. Set initial values for the matrix.

    • If initial values of all elements are the same, enter a real number in the Initial value field. This value applies to all elements of a matrix of any size.

    • If initial values differ, enter real numbers in the Initial value field. For example, you can enter:

      [1 2 3; 4 5 6; 7 8 9]

      Tip   If you want to initialize all elements of a matrix to 0, do nothing. When no values are explicitly defined, all elements initialize to 0.

  5. Click Apply.

  


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