This example is a simple controller for a data path, which assigns the maximum value of two inputs to the output. The M-function is specified as the following and is saved in an M-file xlmax.m:
function z = xlmax(x, y)
if x > y
z = x;
else
z = y;
end
The xlmax.m file needs to be either
saved in the same directory of the model file or in the MATLAB path. After saving the xlmax.m to
the appropriate place, drag an MCode block into your model, open the block parameter dialog
box, and enter xlmax into the MATLAB Function field. After clicking the
OK button, the block has two
input ports x and y, and one output port z.
The following figure shows what the block looks like after the model compiles. You can see that the block calculates and sets the necessary fixed-point data type to the output port.