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 or Model Explorer.
To specify properties in the Property Inspector, open the Property Inspector. In the Modeling tab, in the Design section, select Property Inspector. Click the block to show the properties in the Property Inspector.
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 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 Method | Description |
---|---|
(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. |
Discrete | Sample 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. |
Continuous | Sample 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.
Setting | Action 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. |
Disabled | Generates 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. When you enable this property, you can enable variable-size outputs by enabling the Variable size property on output variables. For more information, see Declare Variable-Size MATLAB Function Block Variables and Variable size.
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
Since R2021b
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.
Treat dimensions of length 1 as fixed size
Since R2023a
Specifies if variables with at least one dimension of length 1 are fixed size. When this property is enabled, the block sets variables that are variable size with a dimension of 1 to fixed size. When this property is disabled, variables in the block that have the Variable size property enabled are always variable size. Prior to R2023a, the block treats variables with at least one dimension of length 1 as fixed size.
This property only affects output variables that have the Variable size property enabled. See Variable size.
Fixed-Point Properties
You can adjust fixed-point properties for the MATLAB Function block in the 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 Designerfi
objects.When you select
Fixed-point & Integer
, the MATLAB Function block treats all fixed-point and integer inputs as Fixed-Point Designerfi
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 afi
object when it is constructed, then thefi
constructor uses the defaultfimath
settings regardless of the properties in MATLAB Function fimath. However, if you perform additional operations on thefi
object after it is constructed, the object will adopt the properties in MATLAB Function fimath.If you specify a
fimath
in thefi
constructor, then thatfimath
is obeyed when quantizing the value in thefi
constructor. Anyfimath
settings not specified in thefi
constructor use the specified properties in MATLAB Function fimath.
You can select one of these options:
Setting | Description |
---|---|
Same as MATLAB | The block uses the same |
Specify other | You can specify your own
For more information, see fimath Object Construction (Fixed-Point Designer) and Fixed-Point Data Types with MATLAB Function Block (Fixed-Point Designer). |
Description and Document Link Properties
You can set description and document link properties for the MATLAB Function block in the 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.
Programmatically Specify Block Properties
You can specify MATLAB Function block properties programmatically by
retrieving the MATLABFunctionConfiguration
or Stateflow.EMChart
objects of the
block. For more information, see Configure MATLAB Function Blocks Programmatically.