Output argument 'x' is not assigned on some execution paths.
Ältere Kommentare anzeigen
Hello, I wrote the following code in the Matlab function in simulink and the error "Outut argument 'x' is not assigned on some execution paths" occurred. I don't know why the code not working. I hope you can help me. Thank you
My simulink function block have this code:
function [x,y] = fcn(u)
% u = battery voltage
% x=1 battery charge switch
% y=1 battery discharge switch
if (u<=0.9) % battery charge
while (u<=1.2)
x=1;
y=0;
end
elseif (u>1.2) || (u>0.9) && (u<1.2) %battery discharge
while (u>=0.9)
x=0;
y=1;
end
else
x=0;
y=0;
end
end
Akzeptierte Antwort
Weitere Antworten (1)
KSSV
am 30 Okt. 2020
You should not use while. Repalce it with if.
function [x,y] = fcn(u)
% u = battery voltage
% x=1 battery charge switch
% y=1 battery discharge switch
if (u<=0.9) % battery charging
if (u<=1.2)
x=1;
y=0;
end
elseif (u>1.2) || (u>0.9) && (u<1.2) %battery discharge
if (u>=0.9)
x=0;
y=1;
end
else
x=0;
y=0;
end
end
8 Kommentare
Serdar GÜNAY
am 30 Okt. 2020
KSSV
am 30 Okt. 2020
Tell me for what input it din't work?
Serdar GÜNAY
am 30 Okt. 2020
Ameer Hamza
am 30 Okt. 2020
It feels like you are not showing the actual code you are running on your PC. The code in KSSV answer will assign values to output variables on all execution paths.
KSSV
am 30 Okt. 2020
You need to rethink on your code...
if (u<=0.9) % battery charging
if (u<=1.2)
x=1;
y=0;
end
elseif
The above line looks ridiculous ...Now as you got to know using while is wrong and you have to use if elseif...you can proceed on your own.
Serdar GÜNAY
am 30 Okt. 2020
KSSV
am 30 Okt. 2020
Hey...it is not you are opposing me...I said it because..now you understood the gist..and you can do it...
Serdar GÜNAY
am 30 Okt. 2020
Kategorien
Mehr zu Sources finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
