Value in m.file does not update with new value presented in simulink

1 回表示 (過去 30 日間)
Armando Marchena
Armando Marchena 2015 年 12 月 9 日
回答済み: Kiran 2015 年 12 月 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

採用された回答

Kiran
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 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by