Main Content

Define MATLAB Function Block Data

You can define the data for MATLAB Function blocks in the MATLAB Function block code, the Ports and Data Manager, or the Model Explorer.

To adjust data in the MATLAB Function block code, double-click the MATLAB Function block to open the MATLAB Function Block Editor. When you specify new input and output arguments, the MATLAB Function block automatically assigns the arguments to the respective input or output port. Similarly, you can remove arguments from the block by deleting them and updating the model.

To use the Ports and Data Manager, double-click the MATLAB Function block to open the MATLAB Function Block Editor. Open the Ports and Data Manager by clicking Ports & Data Manager. You can return to the block code by clicking the Go to Block Editor button Go to Block Editor button.

To use the Model Explorer, in the Modeling tab, in the Design section, click Model Explorer. In the Model Hierarchy pane, expand the model tree view and select the MATLAB Function block.

When using the Ports and Data Manager or the Model Explorer, you can create, manage, and delete data:

  • Modify data properties by selecting the data in the left pane of the Ports and Data Manager or the Contents of pane in the Model Explorer.

  • Add data by clicking Add > Data or the Add Data button Add Data button.

  • Delete data by selecting the data and clicking Edit > Delete or the Delete button Delete button.

Set General Data Properties

After clicking the data you want to modify in the Ports and Data Manager or the Model Explorer, you can set the following properties in the General tab.

Name

Specifies the name of the data argument, using the same naming conventions used in MATLAB®.

Scope

Specifies where data resides in memory relative to its parent. This property determines the range of functionality of the data. You can set Scope to one of the following values:

ScopeDescription
Parameter The data resides in a variable of the same name in the MATLAB workspace, the 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 block uses the variable closest to the block in the workspace hierarchy. For more information, see Model Workspaces.
Input The data is an input signal to a MATLAB Function block.
Output The data is an output signal of a MATLAB Function block.
Data Store Memory The data resides in a Data Store Memory block in the model. For more information, see Storing Data Using Data Store Memory Blocks.

For more information, see Define Input and Output Properties and Configure MATLAB Function Block Parameter Data Arguments.

Port

Specifies the index of the port associated with the data argument. This property applies only to data with the Scope property set to Input or Output.

Data must resolve to signal object

Specifies that the data argument resolves to a Simulink® signal object. This property applies only to data with the Scope property set to Output. This property appears only if you set the configuration parameter Signal resolution to a value other than None. For more information, see Symbol Resolution.

Size

Specifies the size of the data. This property can be a scalar value or a MATLAB vector of values. Size defaults to –1, which means that the size is inherited. For more information, see Inherit Argument Sizes from Simulink. This property does not apply to data with the Scope property set to Data Store Memory. See Specify Size of MATLAB Function Block Data.

Variable size

Specifies whether the size of this data item is variable. This property does not apply to data with the Scope property set to Data Store Memory or Parameter.

Tunable

Specifies whether the parameter used as the source of this data item is tunable. For more information, see Tunable Parameters. This property applies only to data with the Scope property set to Parameter. Clear this option if the parameter must be a constant expression, such as for toolbox functions supported for code generation. For more information, see Functions and Objects Supported for C/C++ Code Generation.

Complexity

Specifies real or complex data arguments. Set Complexity to one of the following values:

ComplexityDescription
InheritedData argument inherits complexity based on the Scope property. 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.
OffData argument is a real number.
On

Data argument is a complex number.

This property does not apply to data with the Scope property set to Data Store Memory.

Type

Specifies the data type for the data. You can specify the data type by:

  • 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 the Mode property, then specifying the data type based on that mode.

    Note

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

For more information, see Specify Argument Types. This property does not apply to data with the Scope property set to Data Store Memory.

Unit (e.g., m, m/s^2, N*m)

Specifies the physical units for data. By default, this property is set to inherit the unit from the Simulink signal on the corresponding input or output port. See Specify Units in MATLAB Function Blocks. The property applies only to data with the Scope property set to Input or Output.

Limit range

Specifies the range of acceptable values for data with the Scope property set to Input or Output. The MATLAB Function block uses this range to validate the data as it enters or leaves the block. You can enter an expression or parameter that evaluates to a numeric scalar.

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

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

Set Description Properties

After clicking the data you want to modify in the Ports and Data Manager or the Model Explorer, you can set the following properties in the Description tab.

Save final value to base workspace

Specifies if the MATLAB Function block assigns the value of the data to a variable of the same name in the MATLAB base workspace after simulation. This property applies only to data with the Scope property set to Input or Output.

Description

Specifies the description of the data argument.

Document link

Specifies the link to the documentation for the data argument. You can enter a URL address or a MATLAB command that displays documentation, such as an HTML file or text in the MATLAB Command Window. When you click the Document link link, the MATLAB Function block evaluates the link and displays the documentation.

See Also

Related Examples

More About