Hello SimTec,
The error message you're encountering indicates that the output variable "pos" is not be assigned a value on some execution paths.
In MATLAB, all output variables need to be assigned a value in every possible execution path of the function. In your current implementation, if "err" is negative, "pos" is not assigned any value, which causes the error.
To fix this, you should initialize both "pos" and "neg" to default values at the beginning of your function. This ensures that they are always assigned, regardless of the condition. Here's how you can modify your function:
function [pos, neg] = select_output(err)
% Initialize outputs
pos = 0;
neg = 0;
% If the error is negative, flow through the PID designed for negative
% errors otherwise positive
if err >= 0
pos = err;
else
neg = err;
end
end
Hope it helps.