This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Scalar Expansion for Converting Scalars to Nonscalars

What Is Scalar Expansion?

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.

How Scalar Expansion Works for Functions

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...
ScalarScalarNo scalar expansion occurs.
Vector or matrixScalarScalar expansion occurs for example(u) to match the dimensions of y.
Vector or matrixVector or matrixScalar expansion occurs so that y[i] = example(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 C charts:

  • MATLAB® functions

  • Graphical functions

  • Simulink® functions

  • Truth table functions

Was this topic helpful?