This example shows how to use the parameter passing mechanism of MCode blocks to specify whether or not to use optional input ports on MCode blocks.
The following M-code, which defines M-function xl_m_addsub is contained in file xl_m_addsub.m:
function s = xl_m_addsub(a, b, sub)
if sub
s = a - b;
else
s = a + b;
end
The following diagram shows a Subsystem containing two MCode blocks
that use M-function xl_m_addsub.
The labeled add is shown in below.
As a result, the add block features
two input ports a and b; it performs full precision addition. Input parameter sub of the MCode block labeled addsub is not bound with any value. Consequently, the addsub block features three input ports: a, b, and sub; it performs full precision addition or subtraction
based on the value of input port sub.