matlabfor-loopvectorsimulink

How can I store dynamically a vector in a For iterator Simulink Subsystem?


I have this simple system:

Simple System

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)):

Upper layer

The loop is:

for i = 1:5

and I want to store the iterator in an array (i.e. [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 I cannot make it work the way I want. How to do it?


Solution

  • I found that there is a tapped delay option. With this option, you can store as a vector (dynamically) various values in Simulink.