Value in m.file does not update with new value presented in simulink
1 次查看(过去 30 天)
显示 更早的评论
In simulink i have a battery system which i would like to monitor using the MATLAB function block. I am using a combination of if and while to monitor certain parts of the system. Unfortunately when the program reaches into the while in order to monitor a parameter in simulink (which is continuously changing), this parameter is not being updated in my m.file meaning that it stays in the loop indefinitely. Is there a way to solve this issue. I included i piece of the code which I'm using as debug at the moment
function [DL_o, PV_o, LS_o] = fcn(SOC, DL, PV, LS)
DL_o = 1;
PV_o = 0;
LS_o = 0;
if ((SOC>=95) && (DL==1) && (PV==0))
disp('Initialization complete')
if ((SOC>20) && (SOC<=100))
disp('System oke')
if (SOC<=95)
disp('Battery charging may start')
if (DL==1)
disp('Dump is OFF')
if (SOC>=99)
disp('Battery is oke')
else
while (SOC<99)
disp('Battery charging (normal)')
if (SOC>=99)
break
end
end
end
end
end
end
end
0 个评论
采纳的回答
Kiran
2015-12-30
Hey,
This is an expected behavior. MATLAB function block is a Non-Virtual block. It executes in atomic mode.
In your model, initial value of SOC must be less than 99, hence it got caught in a infinite while loop. MATLAB function block is not able to compute the output for that time step.
In my opinion, you should be able to replace "while" by "if" statement. That should be able to serve your purpose.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Schedule Model Components 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!