# simple matlab function (simulink) with if?

have written the very basic Matlab function on Simulink and would like why I am getting this error:

function [pos, neg] = select_output(err)
% if the error is negative , flow through the PID designed for negativ
% errors otehrwise positiv
if err >= 0
pos=err;
else
neg=err;
end


You need to assign both defined return values for your function in every possible path. Output argument 'pos' is not assigned on some execution paths tells you exactly the problem. The same also applies for neg by the way.

function [pos, neg] = select_output(err)
% if the error is negative , flow through the PID designed for negativ
% errors otehrwise positiv
if err >= 0
pos=err;
neg = 0;
else
pos = 0;
neg=err;
end


I don't know if assigning 0 to the variable that is not affected by your if-condition is feasible but in the end you need to assign both return values.