Output argument 'ledval1' is not assigned on some execution paths.

here is my code:- function [ledval1,ledval2,ledval3]= checkTorque(Torque) if Torque < 100; ledval1 = led.RED; else if 50 <= Torque < 80; ledval2 = led.YELLOW; else ledval3 = led.BLUE; end end

Answers (1)

Yes, you have three output values - ledval1,ledval2,ledval3. for example, if torque is 60, only ledval2 is assigned. Other two outputs are not assigned.
1. You can set all values to some default value before using if.
function [ledval1,ledval2,ledval3]= checkTorque(Torque)
ledval1='No Colour';ledval2='No Colour';ledval3='No Colour';
if Torque < 100;
ledval1 = led.RED;
else
if 50 <= Torque < 80;
ledval2 = led.YELLOW;
else
ledval3 = led.BLUE;
end
end
or 2. Use one value as output.
function ledval= checkTorque(Torque)
if Torque < 100;
ledval = led.RED;
else
if 50 <= Torque < 80;
ledval = led.YELLOW;
else
ledval = led.BLUE;
end
end

1 Comment

Thanks J Smith I already had second code,Problem is my code is in Simulink as Matlabfunction. but it is not taking some how torque value and that's why I am not getting LED Colors. If you have any idea about it, Please do help me.

Sign in to comment.

Categories

Find more on Simulink in Help Center and File Exchange

Asked:

on 30 Mar 2017

Commented:

on 31 Mar 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!