Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Sizing Function Arguments

Specifying Argument Size

To examine or specify the size of an argument, follow these steps:

  1. From the Embedded MATLAB Editor, select Model Explorer or Tools > Edit Data/Ports.

  2. In the Contents pane, click the row that contains the data argument.

  3. Enter the size of the argument in one of two places:

    • Size field of the Data properties dialog, located in the Dialog pane

    • Size column in the row that contains the data argument, located in the Contents pane

Inheriting Argument Sizes from Simulink

Size defaults to -1, which means that the data argument inherits its size from Simulink based on its scope:

For ScopeInherits Size
InputFrom the Simulink input signal connected to the argument.
OutputFrom the Simulink output signal connected to the argument.
ParameterFrom the Simulink or MATLAB parameter to which it is bound. See Parameter Arguments in Embedded MATLAB Functions.

After you compile the model, the Compiled Size column in the Contents pane displays the actual size used in the compiled simulation application:

The size of an output argument is the size of the value that is assigned to it. If the expected size in the Simulink model does not match, a mismatch error occurs during compilation of the model.

Specifying Argument Sizes with Expressions

The size of a data argument can be a scalar value or a MATLAB vector of values.

To specify size as a scalar, set the Size field to 1 or leave it blank. To specify Size as a vector, enter an array of up to two dimensions in [row column] format where

For example, a value of [2 4] defines a 2-by-4 matrix. To define a row vector of size 5, set the Size field to [1 5]. To define a column vector of size 6, set the Size field to [6 1] or just 6. You can enter a MATLAB expression for each [row column] element in the Size field. Each expression can use one or more of the following elements:

The following examples are valid expressions for Size:

k+1
size(x)
min(size(y),k)

In these examples, k, x, and y are variables of scope Parameter.

Once you build the model, the Compiled Size column in the Contents pane displays the actual size used in the compiled simulation application.

  


Related Products & Applications

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