Adding Data to a MATLAB Function Block

You can define data arguments for MATLAB Function blocks using the following methods:

MethodFor DefiningReference
Define data directly in the MATLAB Function block codeInput and output dataSee Define Inputs and Outputs.
Use the Ports and Data ManagerInput, output, and parameter data in the MATLAB Function block that is open and has focusSee Defining Data in the Ports and Data Manager.
Use the Model ExplorerInput, output, and parameter data in MATLAB Function blocks at all levels of the model hierarchySee Search and Edit Using Model Explorer

Defining Data in the Ports and Data Manager

To add a data argument, in the Ports and Data Manager, select Add > Data and modify the data properties.

Setting General Properties

You can set the following properties in the General tab:

PropertyDescription
NameName of the data argument, following the same naming conventions used in MATLAB®.
Scope

Where data resides in memory, relative to its parent. Scope determines the range of functionality of the data argument. You can set scope to one of the following values:

  • Parameter— Specifies that the source for this data is a variable of the same name in the MATLAB or model workspace or in the workspace of a masked subsystem containing this block. If a variable of the same name exists in more than one of the workspaces visible to the block, the variable closest to the block in the workspace hierarchy is used (see Model Workspaces).

  • Input— Data provided by the model via an input port to the MATLAB Function block.

  • Output— Data provided by the MATLAB Function block via an output port to the model.

  • Data Store Memory— Data provided by a Data Store Memory block in the model.

For more information, see Define Inputs and Outputs and Add Parameter Arguments.

PortIndex of the port associated with the data argument. This property applies only to input and output data.
TunableIndicates whether the parameter used as the source of this data item is tunable (see Tunable Parameters). This property applies only to parameter data. Clear this option if the parameter must be a constant expression, such as for MATLAB toolbox functions supported for code generation (see Functions and Objects Supported for C/C++ Code Generation).
Data must resolve to Simulink signal objectSpecifies that the data argument must resolve to a Simulink® signal object. This property applies only to output data. This property appears only if you set the model configuration parameter Signal resolution to a value other than None. See Symbol Resolution for more information.
SizeSize of the data argument. Size can be a scalar value or a MATLAB vector of values. Size defaults to –1, which means that it is inherited, as described in Inheriting Argument Sizes from Simulink. This property does not apply to Data Store Memory data. For more details, see Size Function Arguments.
Variable SizeIndicates whether the size of this data item is variable. This property does not apply to Data Store Memory data.
ComplexityIndicates real or complex data arguments. You can set complexity to one of the following values:
  • Off— Data argument is a real number

  • On— Data argument is a complex number

  • Inherited— Data argument inherits complexity based on its scope. Input and output data inherit complexity from the Simulink signals connected to them; parameter data inherits complexity from the parameter to which it is bound.

Type
  • Selecting a built-in type from the Type drop down list.

  • Entering an expression in the Type field that evaluates to a data type (see About Data Types in Simulink).

  • Using the Data Type Assistant to specify a data Mode, then specifying the data type based on that mode.

    Note

    To display the Data Type Assistant, click the Show data type assistant button:

For more information, see Specifying Argument Types.
Unit (e.g., m, m/s^2, N*m)

Specify physical units for input and output data. By default, the property is set to inherit the unit from the Simulink signal on the corresponding input or output port. See Units in MATLAB Function Blocks.

Limit range

Specify the range of acceptable values for input or output data. The MATLAB Function block uses this range to validate the input or output as it enters or leaves the block. You can enter an expression or parameter that evaluates to a numeric scalar value.

  • Minimum — The smallest value allowed for the data item during simulation. The default value is -inf.

  • Maximum — The largest value allowed for the data item during simulation. The default value is inf.

Setting Description Properties

You can set the following properties on the Description tab:

PropertyDescription
Save final value to base workspaceThe MATLAB Function block assigns the value of the data argument to a variable of the same name in the MATLAB base workspace at the end of simulation.
DescriptionDescription of the data argument.
Document linkLink to documentation for the data argument. You can enter a Web URL address or a MATLAB command that displays documentation in a suitable format, such as an HTML file or text in the MATLAB Command Window. When you click the blue text, Document link, displayed at the bottom of the Data properties dialog, the MATLAB Function block evaluates the link and displays the documentation.

Related Examples

More About