|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 C charts:
Truth table functions