How can I synchronize a For-Loop in Matlab function with a subsystem in the same simulink model ?

3 次查看(过去 30 天)
Hi, I developpe a Simulink model containing a solar panel subsystem and a Matlab function. In this function I use a loop (for) to calcuate the voltage V(i), then I send it to the panel to get the corresponding output power P(i), which I use to do other calculations. The process is repeated for every iteration i, from 1 to n. Here a part of the program:
for j=1:size(t,1) Vi=t(j,:); sim('model_PV'); new=1/Pi; if new<=old(j) old(j)=new; end end
But I realised that the panel receives only the last value of V(i) (i.e: V(n)) and generates only the corresponding power: P(n). The subsystem does not "see" the other V(i). I think its a problem of synchronization (parallelism) between the loop and the subsystem. I tried to use the function "sim" to execute the subsystem after every generation of V(i) but it does not work (as the function and the subsystem reside in the same model). How can I solve this problem ?
Thank you.

回答(1 个)

TAB
TAB 2018-5-28
Make Vi as array or vector and collect the value from each iteration Vi
tlen = size(t,1);
Vi = zeros(tlen, 1);
for j=1:size(t,1)
Vi(j)=t(j,:);
...
...
end
This will wotk if your "solar panel subsystem" is capable of processing array/vector input.

类别

Help CenterFile Exchange 中查找有关 Subsystems 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by