For Loop Iterator Not working as expected.

조회 수: 4 (최근 30일)
ANKUR WADHWA
ANKUR WADHWA 2019년 3월 20일
댓글: Fangjun Jiang 2019년 3월 25일
i was expecting a staricase signal as the output with final value as 20 which will be displayed on the scope connected as shown in screenshot.
and the XY graph should show the same signal ,however i am not getting the expected behaviour for the scope but the xy graph is getting
plotted correctly ,can someone explain what is going wrong and how it should be corrected to get the defined behaviour.
Main Model
Inside For Iterator Subsystem
For Iterator System Properties
XY Graph Properties
XY Graph After Model Simulation
Scope Output Inside For Iterator Subsystem
Scope output In the Main Model
  댓글 수: 2
madhan ravi
madhan ravi 2019년 3월 21일
편집: madhan ravi 2019년 3월 21일
The link attached is not working, please attach your model.
ANKUR WADHWA
ANKUR WADHWA 2019년 3월 21일
편집: ANKUR WADHWA 2019년 3월 21일
Removed the comma(,) added mistakenly at the end of the link which is working now..
Thanks

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2019년 3월 22일
You need to understand the difference between simulation steps and iteration steps. It looked like you ran simulation for 20 seconds. To simplify, let's assume your simulation step size is 1 second. When the simulation is run at time=1 second, the "For iterator subsystem" is executed 20 times. It itrated from 1 to 20 times. When the 20 iteration is done, the result is output to the Scope. At time=2 second, all these 20 iteration is done again and so is for t=3,4,5,... seconds.
So the Scope in the main modle always show 20. The scope inside the "For iterator subsystem" is also mostly 20 but it also shows the iterator goes back to 1.
XY Graph is different. It just shows the X and Y value pair. Because it is inside the "For Iterator subsystem", it probably shows all the value. But you will get the same graph even if you just ran the simulation for 1 or 2 seconds.
  댓글 수: 2
ANKUR WADHWA
ANKUR WADHWA 2019년 3월 23일
Thanks Fangjun, understood your point , further to this what will be the output of the "For Iterator Block" present inside the "For Iterator Subsystem" within each simulation step as its changing 20 times within each simulation step of 1 sec, I understood from your explanation that the "For Iterator block" is getting iterated 20 times within each simulation step of 1sec but isn't the same "For Iterator Block" is providing the value of X Axis on the graph from 1 to 20 which are then plotted against the Y Values from the increment logic implemented.So when plotted alone on the Scope , i felt it should give a staircase signal changing from 1 to 20 within each simulation step.
Fangjun Jiang
Fangjun Jiang 2019년 3월 25일
The value did change from 1 to 20, but the time logged are all the same as far as Simulink is concerned.
On your Scope (both inside and outside the "For Iterator subsystem" block), go to setting or configuration properties, log the data using "structure with time". Run the simulation for just 1 or 2 steps and observe the data.

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

카테고리

Help CenterFile Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by