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 block, implement
the
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.