Output argument 'x' is not assigned on some execution paths.
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
KSSV
le 30 Oct 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 commentaires
Serdar GÜNAY
le 30 Oct 2020
KSSV
le 30 Oct 2020
Tell me for what input it din't work?
Serdar GÜNAY
le 30 Oct 2020
Ameer Hamza
le 30 Oct 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
le 30 Oct 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
le 30 Oct 2020
KSSV
le 30 Oct 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
le 30 Oct 2020
Catégories
En savoir plus sur Sources dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
