The following usage rules and limitations apply to using System objects in code generated from MATLAB®.
Object Construction and Initialization
If objects are stored in persistent variables, initialize
System objects once by embedding the object handles in an if
statement
with a call to isempty()
.
Set arguments to System object™ constructors as compile-time constants.
You cannot initialize System objects properties with other MATLAB class objects as default values in code generation. You must initialize these properties in the constructor.
Inputs and Outputs
System objects accept a maximum of 1024 inputs. A maximum of 8 dimensions per input is supported.
The data type of the inputs should not change.
If you want the size of inputs to change, verify that
variable-size is enabled. Code generation support for variable-size
data also requires that the Enable variable sizing
option
is enabled, which is the default in MATLAB.
Note:
Variable-size properties in MATLAB
Function block in Simulink® are not supported. System
objects predefined in the software do not support variable-size if
their data exceeds the |
Do not set System objects to become outputs from the MATLAB Function block.
Do not use the Save and Restore Simulation State as SimState option for any System object in a MATLAB Function block.
Do not pass a System object as an example input
argument to a function being compiled with codegen
.
Do not pass a System object to functions declared
as extrinsic (functions called in interpreted mode) using the coder.extrinsic
function.
System objects returned from extrinsic functions and scope System
objects that automatically become extrinsic can be used as inputs
to another extrinsic function, but do not generate code.
Tunable and Nontunable Properties
The value assigned to a nontunable property must be a constant and there can be at most one assignment to that property (including the assignment in the constructor).
For most System objects, the only time you can set their nontunable properties during code generation is when you construct the objects.
For System objects that are predefined in the software, you can set their tunable properties at construction time or using dot notation after the object is locked.
For System objects that you define, you can change
their tunable properties at construction time or using dot notation
during code generation. For getNumInputsImpl
and getNumOutputsImpl
methods,
if you set the return argument from an object property, that object
property must have the Nontunable
attribute.
Objects cannot be used as default values for properties.
Global Variables
Global variables are allowed in a System object, unless you will be using that System object in Simulink via the MATLAB System block. To avoid syncing global variables between a MEX file and the workspace, use a coder configuration object. For example:
f = coder.MEXConfig;
f.GlobalSyncMethod = 'NoSync'
'-config
f'
in your codegen
command.Methods
Code generation support is available only for these System object methods:
get
getNumInputs
getNumOutputs
isDone
(for sources only)
isLocked
release
reset
set
(for tunable properties)
step
For System objects that you define,
Code generation support is available only for these methods:
getDiscreteStateImpl
getNumInputsImpl
getNumOutputsImpl
infoImpl
isDoneImpl
isInputDirectFeedThroughImpl
outputImpl
processTunedPropertiesImpl
releaseImpl
— Code is not
generated automatically for this method. To release an object, you
must explicitly call the release
method in your code.
resetImpl
setupImpl
stepImpl
updateImpl
validateInputsImpl
validatePropertiesImpl