Main Content

Specify MATLAB Function Block Properties

You can specify how a MATLAB Function block interfaces with a Simulink® model by setting the block properties in the Property Inspector, Ports and Data Manager, or Model Explorer.

To specify properties in the Property Inspector, click the Modeling tab. In the Design section, select Property Inspector. Click the MATLAB Function block to see the MATLAB Function block properties.

To specify properties in the Ports and Data Manager, double click the MATLAB Function block to open the MATLAB Function Block Editor. Click Ports & Data Manager. To access the MATLAB Function block properties, click the Show Block Dialog button Show Block Dialog button.

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

MATLAB Function Block Properties

You can adjust the following properties in the Ports and Data Manager and the Model Explorer, or by navigating to the Properties tab of the Property Inspector.

Update method

Specifies the method used for activating the MATLAB Function block.

Update MethodDescription

Inherited

(default)

Input from the Simulink model activates the MATLAB Function block.

If you define an input trigger, the MATLAB Function block executes in response to a Simulink signal or function-call event on the trigger port. If you do not define an input trigger, the MATLAB Function block implicitly inherits triggers from the model. These implicit events are the sample times (discrete or continuous) of the signals that provide inputs to the block.

If you define data inputs, the MATLAB Function block samples at the rate of the fastest data input. If you do not define data inputs, the MATLAB Function block samples at the rate defined by the execution behavior of the parent subsystem.

DiscreteSample the MATLAB Function block using the rate you specify in the Sample time property of the MATLAB Function block. The MATLAB Function block generates an implicit event at regular time intervals that correspond to the specified rate. Note that other blocks in the model can have different sample times.
ContinuousSample the MATLAB Function block at each major time step of the simulation, as well as at intermediate time points requested by the Simulink solver.

Saturate on integer overflow

Specifies how the MATLAB Function block handles overflow conditions during integer operations.

SettingAction When Overflow Occurs

Enabled

(default)

Saturates an integer by setting it to the maximum positive or negative value allowed by the word size. This setting matches MATLAB® behavior.
DisabledGenerates a run-time error in simulation mode. For Simulink Coder™ code generation, the behavior depends on your C language compiler.

Note

The Saturate on integer overflow option is relevant only for integer arithmetic. It has no effect on fixed-point or double-precision arithmetic.

When you enable Saturate on integer overflow, MATLAB adds additional checks during simulation to detect integer overflow or underflow. Therefore, it is more efficient to disable this option if you are sure that integer overflow and underflow does not occur in your MATLAB Function block code.

Note that the code generated by Simulink Coder does not check for integer overflow or underflow and, therefore, may produce unpredictable results when Saturate on integer overflow is disabled. In this situation, simulate your model to test for overflow and underflow before generating code.

Support variable-size arrays

Specifies if the MATLAB Function block supports input and output data that varies in dimension during simulation. For more information, see Declare Variable-Size Inputs and Outputs.

Allow direct feedthrough

Specifies if the MATLAB Function block supports direct feedthrough semantics, so that the output of the block is controlled directly by the value of an input. When you disable Allow direct feedthrough, nondirect feedthrough semantics ensure that outputs rely only on the current state of the block. Using nondirect feedthrough enables you to use MATLAB Function blocks in a feedback loop and prevent algebraic loops. For more information, see Use Nondirect Feedthrough in a MATLAB Function Block.

Interpret output column vectors as one-dimensional data

Specifies if the output of a column vector evaluates as one-dimensional data.

  • If you enable this property, the block converts output column vectors of size N-by-1 to one-dimensional signals with a signal size equal to N.

  • If you disable this property, the block outputs column vectors of size N-by-1 as signals with a signal size equal to N-by-1.

Note

Before R2021b, MATLAB Function blocks always converted output column vectors to one-dimensional signals.

Fixed-Point Properties

You can adjust fixed-point properties for the MATLAB Function block in the Ports and Data Manager and Model Explorer, or by navigating to the Fixed-point properties section in the Properties tab of the Property Inspector.

Treat these inherited Simulink signal types as fi objects

Specifies whether to treat inherited fixed-point and integer signals as Fixed-Point Designer™ fi (Fixed-Point Designer) objects. For more information, see Ways to Construct fi Objects (Fixed-Point Designer).

  • When you select Fixed-point, the MATLAB Function block treats all fixed-point inputs as Fixed-Point Designer fi objects.

  • When you select Fixed-point & Integer, the MATLAB Function block treats all fixed-point and integer inputs as Fixed-Point Designer fi objects.

MATLAB Function fimath

Specifies fimath properties for the MATLAB Function block. The fimath on a MATLAB Function block behaves as a globalfimath (Fixed-Point Designer) for the contents of the MATLAB Function block. The block associates the fimath properties in MATLAB Function fimath with all fixed-point and integer input signals to the MATLAB Function block that you choose to treat as fi objects. Constructing fi objects in the MATLAB Function block introduces additional considerations.

  • If no fimath is associated with a fi object when it is constructed, then the fi constructor uses the default fimath settings regardless of the properties in MATLAB Function fimath. However, if you perform additional operations on the fi object after it is constructed, the object will adopt the properties in MATLAB Function fimath.

  • If you specify a fimath in the fi constructor, then that fimath is obeyed when quantizing the value in the fi constructor. Any fimath settings not specified in the fi constructor use the specified properties in MATLAB Function fimath.

You can select one of these options:

SettingDescription
Same as MATLAB

The block uses the same fimath properties as the current default fimath. The edit box is dimmed and displays the current global fimath in read-only form.

Specify other

You can specify your own fimath (Fixed-Point Designer) object in the edit box. You can do so in one of two ways:

  • Constructing the fimath object inside the edit box.

  • Constructing the fimath object in the MATLAB or model workspace and then entering its variable name in the edit box. If you use this option and plan to share your model with others, define the variable in the model workspace. See Sharing Models with Fixed-Point MATLAB Function Blocks (Fixed-Point Designer).

For more information on fimath objects, see fimath Object Construction (Fixed-Point Designer).

Description and Document Link Properties

You can set description and document link properties for the MATLAB Function block in the Ports and Data Manager or Model Explorer, or by navigating to the Info tab of the Property Inspector.

Description

Specifies the description of the MATLAB Function block. You can enter a brief description and comments.

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