MATLAB: Output argument ‘ua’ is not assigned on some execution paths.

assigned error

I use matlab function block in simulink and got tihs error. Here is my code and error messages
function [ua, ub] = fcn(u)
if (u >= 0)
ub=0;
else
ua=0;
end
Output argument 'ua' is not assigned on some execution paths. Function 'MATLAB Function' (#24.10.12), line 1, column 11: "ua" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'Qz1/MATLAB Function'
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'Qz1/MATLAB Function'
Component:Simulink | Category:Model error

Best Answer

When the condition is not satisfied either of the variable ua, ub is not defined; so you will get error. You must define them first. You have to define ua and ub first as you are taking the output. Try like this:
function [ua, ub] = fcn(u)
ua = NaN ; ub = NaN ;
if (u >= 0)
ub=0;
else
ua=0;
end