Main Content

Adding Data to a MATLAB Function Block

You can define data arguments forMATLAB Functionblocks using the following methods:

Method For Defining Reference
Define data directly in theMATLAB Functionblock code Input and output data SeeDefine Inputs and Outputs.
Use the Ports and Data Manager Input, output, and parameter data in theMATLAB Functionblock that is open and has focus SeeDefining Data in the Ports and Data Manager.
Use the Model Explorer Input, output, and parameter data inMATLAB Functionblocks at all levels of the model hierarchy SeeModel Explorer

Defining Data in the Ports and Data Manager

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

Setting General Properties

You can set the following properties in the General tab:

Property Description
Name Name 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 (seeModel Workspaces).

  • Input— Data provided by the model via an input port to theMATLAB Functionblock.

  • Output— Data provided by theMATLAB Functionblock via an output port to the model.

  • Data Store Memory— Data provided by aData Store Memoryblock in the model (seeStoring Data Using Data Store Memory Blocks).

For more information, seeDefine Inputs and OutputsandAdd Parameter Arguments.

Port argumen指数相关的端口数据t. This property applies only to input and output data.
Tunable Indicates whether the parameter used as the source of this data item is tunable (seeTunable 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 (seeFunctions and Objects Supported for C/C++ Code Generation).
Data must resolve to Simulink signal object Specifies 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 parameterSignal resolutionto a value other thanNone. SeeSymbol Resolutionfor more information.
Size Size 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 inInheriting Argument Sizes from Simulink. This property does not apply to Data Store Memory data. For more details, seeSize Function Arguments.
Variable Size Indicates whether the size of this data item is variable. This property does not apply to Data Store Memory data.
Complexity

Indicates 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 theTypedrop down list.

  • Entering an expression in theTypefield that evaluates to a data type (seeAbout Data Types in Simulink).

  • Using the Data Type Assistant to specify a dataMode, 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, seeSpecifying 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. SeeUnits in MATLAB Function Blocks.

Limit range

为输入o指定可接受的值的范围内r output data. TheMATLAB Functionblock 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 isinf.

Setting Description Properties

You can set the following properties on the Description tab:

Property Description
Save final value to base workspace TheMATLAB Functionblock assigns the value of the data argument to a variable of the same name in the MATLAB base workspace at the end of simulation.
Description Description of the data argument.
Document link Link 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 theDataproperties dialog, theMATLAB Functionblock evaluates the link and displays the documentation.

Related Examples

More About