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

3 views (last 30 days)
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.

Answers (1)

TAB
TAB on 28 May 2018
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.

Products

Community Treasure Hunt

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

Start Hunting!