0
\$\begingroup\$

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

enter image description here

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.