Main Content

Integration Considerations for MATLAB Function Blocks

Use Nondirect Feedthrough in a MATLAB Function Block

In Simulink® blocks, direct feedthrough means that the output of a block is controlled directly by the value of an input port signal. In nondirect feedthrough, the value of the output signal does not depend on the value of the input signal in at least one function during the simulation.

By default, MATLAB Function blocks have direct feedthrough enabled. If you disable direct feedthrough, the Simulink semantics ensure that outputs rely only on current state. Using nondirect feedthrough enables you to use MATLAB Function blocks in a feedback loop and prevent algebraic loops.

To use nondirect feedthrough:

  • Enable function inlining of the MATLAB Function block by using coder.inline in the top-level function body.

  • Open the properties for the MATLAB Function block and clear Allow direct feedthrough. For more information, see Specify MATLAB Function Block Properties.

Limitations of Nondirect Feedthrough

Do not program outputs to rely on inputs or updated persistent variables. For example, do not use this code in a nondirect feedthrough block:

counter = counter + 1;  	% update state
output = counter;       	% compute output based on updated state
Instead, use this code:
output = counter;       	% compute output based on current state
counter = counter + 1;  	% update state
For more information, see Initialize Persistent Variables in MATLAB Functions.

If Allow direct feedthrough is disabled, you cannot call custom code functions in MATLAB Function blocks because it is not possible to enforce that the outputs of custom code functions depend only on the current state. Calling a custom code function in a MATLAB Function block triggers an error.

See Also

Related Topics