Main Content

Define MATLAB Function Block Data

You can define the data forMATLAB Functionblocks in theMATLAB Functionblock code, the Ports and Data Manager, or the Model Explorer.

To adjust data in theMATLAB Functionblock code, double-click theMATLAB Functionblock to open theMATLAB Function Block Editor. When you specify new input and output arguments, theMATLAB Functionblock 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 theMATLAB Functionblock to open theMATLAB Function Block Editor. Open the Ports and Data Manager by clicking端口和数据管理器. You can return to the block code by clicking the Go to Block Editor buttonGo to Block Editor button.

To use the Model Explorer, in theModelingtab, in theDesignsection, clickModel Explorer. In theModel Hierarchypane, expand the model tree view and select theMATLAB Functionblock.

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 theContents ofpane in the Model Explorer.

  • Add data by clickingAdd>Dataor the Add Data buttonAdd Data button.

  • 删除data by selecting the data and clickingEdit>删除or the Delete button删除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 theGeneraltab.

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 setScopeto one of the following values:

Scope Description
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, seeModel Workspaces.
Input The data is an input signal to aMATLAB Functionblock.
Output The data is an output signal of aMATLAB Functionblock.
Data Store Memory The data resides in aData Store Memoryblock in the model. For more information, seeStoring Data Using Data Store Memory Blocks.

For more information, seeDefine Input and Output PropertiesandConfigure 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 theScopeproperty set toInputorOutput.

Data must resolve to signal object

Specifies that the data argument resolves to a Simulink®signal object. This property applies only to data with theScopeproperty set toOutput. This property appears only if you set the configuration parameterSignal resolutionto a value other thanNone. For more information, seeSymbol Resolution.

大小

Specifies the size of the data. This property can be a scalar value or a MATLAB vector of values.大小defaults to–1, which means that the size is inherited. For more information, seeInherit Argument Sizes from Simulink. This property does not apply to data with theScopeproperty set toData Store Memory. SeeSpecify 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 theScopeproperty set toData Store MemoryorParameter.

Tunable

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

Complexity

Specifies real or complex data arguments. SetComplexityto one of the following values:

Complexity Description
Inherited Data argument inherits complexity based on theScopeproperty. 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.
Off Data argument is a real number.
On

Data argument is a complex number.

这个属性并不适用于数据Scopeproperty set toData Store Memory.

Type

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

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

    Note

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

For more information, seeSpecify Argument Types. This property does not apply to data with theScopeproperty set toData 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. SeeSpecify Units in MATLAB Function Blocks. The property applies only to data with theScopeproperty set toInputorOutput.

Limit range

Specifies the range of acceptable values for data with theScopeproperty set toInputorOutput. TheMATLAB Functionblock 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 isinf.

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 theDescriptiontab.

Save final value to base workspace

Specifies if theMATLAB Functionblock 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 theScopeproperty set toInputorOutput.

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 theDocument linklink, theMATLAB Functionblock evaluates the link and displays the documentation.

See Also

Related Examples

More About