Considerations for Using System Objects in Simulink
There are differences in how you can use System objects in a MATLAB System block in Simulink® versus using the same object in MATLAB®. You see these differences when working with variable-size signals and tunable parameters and when using System objects as properties.
Variable-Size Signals
To use variable-size signals in a System object™, you must implement propagation methods. In particular, use the
isOutputFixedSizeImpl
method to specify if an output is
variable-size or fixed-size. This method is needed for interpreted execution and
code generation simulation methods.
Tunable Parameters
Simulink registers public tunable properties of a System object as tunable parameters of the corresponding MATLAB System block. If a System object property is tunable, it is also tunable in the MATLAB System block. At runtime, you can change the parameter using one of the following approaches. The change applies at the top of the simulation loop.
At the MATLAB command line, use the
set_param
to change the parameter value.In the Simulink editor, edit the MATLAB System block dialog box to change the parameter value, and then update the block diagram.
You cannot change public tunable properties from System object internal methods such as stepImpl
.
During simulation, setting an invalid value on a tunable parameter causes an error message and stops simulation.
System Objects as Properties
The MATLAB System block allows a System object to have other System objects as public or private properties. However:
System objects and other MATLAB objects stored as public properties are read only. As a result, you cannot set the value of the parameter, you can only get the value of a parameter.
System objects stored as property values appear dimmed in the MATLAB System block dialog box.
Default Property Values
MATLAB does not require that objects assign default values to properties. However, in Simulink, if your System object has properties with no assigned default values, the associated dialog box parameter requires that the value data type be a built-in Simulink data type.
System Objects in For Each Subsystems
To use the MATLAB System block within a For Each Subsystem block, implement
the supportsMultipleInstanceImpl
method. This method should return true
. The MATLAB
System block clones the System object for each For Each Subsystem iteration.
Input Validation
In Simulink, use the validateInputsImpl
method
to validate only attributes (size, data type, and complexity) of the input. Do not
use this method to validate the value of the input.
See Also
Related Examples
- Implement a MATLAB System Block
- Change Blocks Implemented with System Objects
- Change Block Icon and Port Labels
- Add and Implement Propagation Methods
- Use System Objects in Feedback Loops
- Troubleshoot System Objects in Simulink