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

조회 수: 4 (최근 30일)
Matthew Tieu
Matthew Tieu 2022년 11월 23일
편집: Matthew Tieu 2022년 12월 8일
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
Matthew Tieu
Matthew Tieu 2022년 12월 8일
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 2022년 12월 8일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen Eltinge
Stephen Eltinge 2022년 12월 8일
편집: Stephen Eltinge 2022년 12월 8일
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
Matthew Tieu
Matthew Tieu 2022년 12월 8일
편집: Matthew Tieu 2022년 12월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by