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

asked Nov 13, 2019 at 7:03
\$\endgroup\$

1 Answer 1

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.

answered Nov 13, 2019 at 10:27
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.