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.

  • In the Ports and Data Manager, in the MATLAB Function Block Editor, select Edit Data on the Editor tab and clear the Allow direct feedthrough check box. For more information, see Ports and Data Manager.


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

See Also

Related Topics