| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Stateflow |
| Contents | Index |
| Learn more about Stateflow |
| On this page… |
|---|
Scalar expansion is a method of converting scalar data to match the dimensions of vector or matrix data. For example, scalar expansion can convert a value of 1 to a vector or matrix where all the elements are 1.
Suppose that you have a function signature yy = example(uu), where the formal arguments yy and uu are scalars. Assume that you have a function call y = example(u). The rules of scalar expansion for function calls with a single output follow.
| If the output y is a... | And the input u is a... | Then... |
|---|---|---|
| Scalar | Scalar | No scalar expansion occurs. |
| Vector or matrix | Scalar | Scalar expansion occurs for example(u) to match the dimensions of y. |
| Vector or matrix | Vector or matrix | Scalar expansion occurs so that y[i] = example(u[i]). |
| Scalar | Vector or matrix | An error message alerts you to a size mismatch. |
For functions with multiple outputs, the same rules apply except for the case where the outputs and inputs of the function call are all vectors or matrices. In this case, scalar expansion does not occur, and an error message alerts you to a size mismatch.
The rules of scalar expansion apply to all functions that you use in Stateflow charts:
Embedded MATLAB functions (see Using Embedded MATLAB Functions in Stateflow Charts)
Graphical functions (see Using Graphical Functions to Extend Actions)
Simulink functions (see Using Simulink Functions in Stateflow Charts)
Truth table functions (see Truth Table Functions)
![]() | How to Define Vectors and Matrices | How to Assign and Access Values of Vectors and Matrices | ![]() |

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 |