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

131 ビュー (過去 30 日間)
Napat Chuntararuangnapa
Napat Chuntararuangnapa 2017 年 4 月 14 日
回答済み: KNourdine 2021 年 11 月 4 日
I use matlab function block in simulink and got tihs error. Not sure if it's my code or something because I've never use this function block before. Here is my code;
function t = fcn(tr, soc)
if(tr<=20)
if(soc<=0.25)
t=tr+5;
elseif(0.25<soc<=0.5)
t=0;
elseif(0.5>soc)
t=0;
end
elseif(20<tr<=30)
if(soc<=0.25)
t=tr+5;
elseif(0.25<soc<=0.5)
t=tr-5;
elseif(0.5>soc)
t=tr-10;
end
elseif(tr>30)
if(soc<=0.25)
t=tr+10;
elseif(0.25<soc<=0.5)
t=tr-10;
elseif(0.5>soc)
t=tr-0;
end
end
end
Thank you

採用された回答

Aniruddha Katre
Aniruddha Katre 2017 年 4 月 14 日
Here, the variable t is an output from the MATLAB Function block. It needs to have a value at each time step of the simulation. Currently, you have an if-condition and an else-if condition based on "tr" where a value is assigned to "t".
What if "tr" does not satisfy either of the two conditions? In that case the output variable t will not be assigned a value. There are blocks downstream that depend on the output of the MATLAB Function block. If a value to t is not assigned, then those blocks cannot execute and hence the error message.
To fix this you need an "else" condition (a catch-all) that assigns a default value to t if neither the if or else-if conditions are met.

その他の回答 (1 件)

KNourdine
KNourdine 2021 年 11 月 4 日
elseif(0.5>soc) should be elseif(0.5<soc)

Community Treasure Hunt

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

Start Hunting!

Translated by