how can i get two variables to meet the target SOC which is calculated from simulink.

1 vue (au cours des 30 derniers jours)
open_system(mdl)
soc_target = 78.6
off_line = 3000
on_line = 7000
sim(mdl);
while true
sim(mdl);
soc_fin = ans.soc_fin;
if abs(soc_fin(end)-soc_target) <= 1.5
break;
end
on_line = on_line + 1000;
end
on_line
off_line
while true
sim(mdl);
soc_fin = ans.soc_fin;
if soc_fin(end)-soc_target < -0.1
off_line = off_line - 100;
elseif soc_fin(end)-soc_target > -0.1
off_line = off_line + 100;
else abs(soc_fin(end)-soc_target) <= 0.1
break
end
end
on_line
off_line
while true
sim(mdl);
soc_fin = ans.soc_fin;
if soc_fin(end)-soc_target < -0.01
off_line = off_line - 10;
elseif soc_fin(end)-soc_target > -0.01
off_line = off_line + 10;
else abs(soc_fin(end)-soc_target) <= 0.01
break
end
end
on_line
off_line
above code is mine that to find
variables on_line & off_line is a number and in simulink model, SOC will be calculated.
when the variables increase, SOC will be decreased,
As variables increase, the soc value decreases, and similarly, as variables decrease, the soc value increases.
i want find two variables to meet SOC target
i'm newly user of matlab so my code is poor
please help.

Réponses (1)

Ram Prasanth
Ram Prasanth le 19 Avr 2024
Hello @Youngjin,
One idea is to integrate your code in the s-function in your simulink file.
Through this idea you can update your variable and your simulink file will run along with the updated values.
You can find the documentation for it in this link - What Is an S-Function? - MATLAB & Simulink - MathWorks France.

Community Treasure Hunt

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

Start Hunting!

Translated by