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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Kiran
Kiran am 30 Dez. 2015
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.

Weitere Antworten (0)

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by