Documentation

## Add Vector and Matrix Data

### Define a Vector

Define a vector in a Stateflow chart as follows:

1. Add data to your chart as described in Add Stateflow 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.

### Note

Vectors cannot have the base type `ml`. See Rules for Vectors and Matrices in Stateflow Charts.

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 .

### Define a Matrix

Define a matrix in a Stateflow chart as follows:

1. Add data to your chart as described in Add Stateflow 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.

### Note

Matrices cannot have the base type `ml`. See Rules for Vectors and Matrices in Stateflow Charts.

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 .

## Related Topics

##### Support Get trial now