MATLAB: Add a function to a model

s-function if-else

Hi, I develop a function in matlab code:
function u = f(y)
if (u>0.8)
y=1;
elseif (u<0.8)
y=-1;
else
y=0;
where u is a random signal generate with the random number block. How can i join these two blocks? (random number and a block which contain my function without errors). I try using level-2 matlab s-function but it make error. can i use another block in which i introduce my matlab function code?
Thanks in advance. NĂ©stor

Best Answer

Use the "MATLAB Fcn" or "Fcn" block from library Simulink>User-Defined Functions.