Clear Filters
Clear Filters

I receive an error when adding a delay block in for loop block

3 views (last 30 days)
Hi,
I am making a for loop. To make the variation in vector values visible on the scope, I have added a transport delay block after the iterator block as seen in the image below.
The problem, is that when I run the Simulink program, I receive an error which says:
'Loops_in_Simulink/For Iterator Subsystem/Transport Delay' has sample time 0. Sample time of block must be inherited (-1) because blocks in a triggered subsystem must run only when the triggered subsystem runs.
If I double click on the transport delay block, I cannot see an option to change the sample time. This program is not a homework task. Could someone let me know how I could change the sample time? Thanks in advance.
  5 Comments
Matthew Tieu
Matthew Tieu on 8 Dec 2022
I know for modelling continuous systems, the transport delay block adds a specified period of zero output to the start of an input signal. I need a block that can add a specified time delay to each iteration of the for loop.
In other words, there should be a delay of T seconds before the output changes from the nth value to the (n+1)th value of the vector. Is there a block that can achieve this?
Fangjun Jiang
Fangjun Jiang on 8 Dec 2022
You are doing a 1:n for-loop. At the end of 1st loop, the value of output O(1) is obtained. At the end of 2nd loop, the value of output O(2) is obtained. You want "a delay of T seconds" between O(1) and O(2)??
But you should know, that in Simulink, all the for-loops, from 1 to n, are all calculated and finished in the same time step. There isn't a concept of "time delay" if your original problem is modeled and simulated this way.
If you want to insert some values between O(1) and O(2), then the "Vector Concatenate" block can be used.
But overall, I suspect that your original problem was modeled wrong. Your intended usage of the "For Iterator" block missed the mark. The output is a number (1 to N, depending on the loop) at the end of each loop. The output could be hidden (no ouptut at all). Please read the document to understand it.

Sign in to comment.

Accepted Answer

Stephen Eltinge
Stephen Eltinge on 8 Dec 2022
Edited: Stephen Eltinge on 8 Dec 2022
Hi Matthew,
Fangjun is correct in the comments above. Be careful not to confuse two different concepts: the timesteps of the top-level model and the iterations of the For Iterator Subsystem. At each model timestep, the For Iterator Subsystem executes its entire contents as many times as you specify, then reports the final output. The Display block does not update during this calculation.
It seems to me that what you are trying to do is construct a model that acts element-by-element on an array and prints some result to the Display block after every step. Instead, your current model processes the entire 1x31 array at every timestep and reports the same final answer. If you want to act on one element per timestep, you need to construct a time-varying signal. See the Signal From Workspace block for a simple way to import or construct a signal from raw data.
  1 Comment
Matthew Tieu
Matthew Tieu on 8 Dec 2022
Edited: Matthew Tieu on 8 Dec 2022
Thanks for the reply, it looks like it is not possible to implement a delay per iteration directly in the for loop. I will probably use an X-Y graph block and a 'Vector Concatenate' block instead in that case.

Sign in to comment.

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!