Passing through enabled subsystems in a for-loop
64 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Hitesh
el 19 de Nov. de 2024 a las 10:09
Could you share the simulink file so that we can investiagte the root cause of this issue ?
Respuestas (1)
Hitesh
el 20 de Nov. de 2024 a las 14:08
Editada: Hitesh
hace alrededor de 13 horas
"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:
- Double-click on the "Second Enabled Subsystem."
- Double-click on the "Vector2" Outport block.
- The Block Parameter dialog will open.
- Set the Initial Output vector to [0 0 0].
- 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:
0 comentarios
Ver también
Categorías
Más información sobre Subsystems en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!