Passing through enabled subsystems in a for-loop

조회 수: 68 (최근 30일)
John
John 2024년 11월 19일 8:23
편집: Hitesh 2024년 11월 21일 5:13
Hi,
I have two enabled subsystems inside a for-loop, which has the number of iterations of 3. The first subsystem is enabled when iteration = 1 and 2. The second subsystem is enabled when iteration = 3. The model is below. A vector initialized to be [0 0 0] is passed through the first subsystem and assigned the value of iteration to the elements to make it Vector1. Vector1 is then passed through the second subsystem and assigned the value of 2*iteration to make it Vector 2. I use the selector and assignment to be able to monitor all elements of the vectors for each iteration. I could see that Vector1 is consistent with my expectation but Vector2 is not.
- In the first iteration, first enabled subsystem is enabled, Vector1 should be [1, 0, 0]. Second enabled subsystem is disabled, Vector2 should be [1, 0, 0] but it shows [1 2 6]
- In the second iteration, first enabled subsystem is enabled, Vector 1 should be [1, 2, 0]. Second enabled subsystem is disabled, Vector2 should be [1, 2, 0] but it shows [1 2 6]
- In the third iteration, first enabled subsystem is disabled, Vector 1 should be [1, 2, 0]. Second enabled subsystem is enabled, Vector2 should be [1, 2, 6] and it also shows [1 2 6]
It looks like for Vector2, the value for the last iteration is back-assigned to the previous iterations. Any explanation is appreciated.
  댓글 수: 2
Hitesh
Hitesh 2024년 11월 19일 10:09
Hi @John,
Could you share the simulink file so that we can investiagte the root cause of this issue ?
John
John 2024년 11월 19일 15:32
편집: John 2024년 11월 19일 15:32
I have uploaded the Simulink file with the original post. Thank you

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

답변 (1개)

Hitesh
Hitesh 2024년 11월 20일 14:08
편집: Hitesh 2024년 11월 21일 5:13
Hi @John,
"Vector2" is inconsistent because it retains the previous timestamp vector value, which in this case is "[1 2 6]". You can confirm this by setting a breakpoint on the iteration signal and repeatedly clicking the step forward button. After the first timestamp completes, you will notice that the "Vector2" still holds the previous timestamp value. I have attached an image for your reference.
However, if you wish to reset the value of "Vector2" before beginning the first iteration of each timestamp, please follow these steps:
  1. Double-click on the "Second Enabled Subsystem."
  2. Double-click on the "Vector2" Outport block.
  3. The Block Parameter dialog will open.
  4. Set the Initial Output vector to [0 0 0].
  5. Update and save the model.
The results for both Vector1 and Vector2 during each iteration for every timestamp will be as follows:
  • In the first iteration, the "First Enabled Subsystem" is active, so "Vector1" should be [1 0 0]. The "Second Enabled Subsystem" is inactive, so "Vector2" should be [0 0 0], and it indeed shows [0 0 0].
  • In the second iteration, the "First Enabled Subsystem" remains active, making "Vector1" [1 2 0]. The "Second Enabled Subsystem" is still inactive, so "Vector2" should be [0 0 0], and it displays [0 0 0].
  • In the third iteration, the "First Enabled Subsystem" is inactive, keeping "Vector1" at [1 2 0]. Meanwhile, the "Second Enabled Subsystem" is active, so "Vector2" should be [1 2 6], and it correctly displays [1 2 6].
I have attached the " Revised_For_Loop_Sequence_Enabled_Subsystem.slx" for your reference.
For more information regarding "Debuging Simulation Using Signal Breakpoints", kindly refer to the below MATLAB Documentation:

카테고리

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

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by