Passing through enabled subsystems in a for-loop

64 Ansichten (letzte 30 Tage)
John
John am 19 Nov. 2024 um 8:23
Bearbeitet: Hitesh vor etwa 14 Stunden
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 Kommentare
Hitesh
Hitesh am 19 Nov. 2024 um 10:09
Hi @John,
Could you share the simulink file so that we can investiagte the root cause of this issue ?
John
John am 19 Nov. 2024 um 15:32
Bearbeitet: John am 19 Nov. 2024 um 15:32
I have uploaded the Simulink file with the original post. Thank you

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Hitesh
Hitesh am 20 Nov. 2024 um 14:08
Bearbeitet: Hitesh vor etwa 14 Stunden
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:

Kategorien

Mehr zu Subsystems finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by