- The for-loop can be implemented inside the MATLAB Function block.
- Keep in mind, the simulation runs along the time. At every time step, the whole model runs. The MATLAB Function block is executed at every time step. So if you have a for-loop inside the MATLAB Function block, the output is propagated after the for-loop is finished.
- Most likely, you don't need the for-loop inside the MATLAB Function block. Code can be written to deal with the 1x5 vector input directly.
How to store dynamically an array in a For iterator Simulink Subsystem
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have this simple system:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304495/image.jpeg)
The code in the function is:
function a = fcn(iteration,a)
a(1,iteration) = iteration;
end
The outside Simulink layer is the following (a is initialized as a = zeros(1,5)):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/304499/image.jpeg)
The loop is a
for i = 1:5
and I want to store the iterator in an array (ie [1 2 3 4 5]), but for some reason Simulink initializes the array at every iterator step for a single time step, so I can only see the last value.
I have tried many different combinations, but nothing works. Do you know how I could do it?
Thank you in advance,
Christos
0 Kommentare
Antworten (1)
Fangjun Jiang
am 28 Mai 2020
I know this might be a simple example behind your real need. But this is unnecessary.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Subsystems 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!