This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Convert Scalars to Nonscalars by Using Scalar Expansion

Scalar expansion is a method of converting scalar data to match the dimensions of vector or matrix data. For example, in this assignment, scalar expansion converts a value of 1 to a vector or matrix where all the elements are 1:

A = 1;

Scalar expansion is supported only in Stateflow® charts that use C as the action language.

How Scalar Expansion Works for Functions

Suppose that you have a function signature yy = f(uu), where the formal arguments yy and uu are scalars. Assume that you have a function call y = f(u). The rules of scalar expansion for function calls with a single output follow.

Output yInput uResult
ScalarScalarNo scalar expansion occurs.
Vector or matrixScalarScalar expansion occurs for f(u) to match the dimensions of y.
Vector or matrixVector or matrixScalar expansion occurs so that y[i] = f(u[i]).
ScalarVector or matrixAn 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:

  • MATLAB® functions

  • Graphical functions

  • Simulink® functions

  • Truth table functions

Related Topics