Rukmani Mohan
Rukmani Mohan

Reputation: 13

FOR iterator block in Simulink

I have a Simulink model which has to do the following: In1 input would take in a vector of 3 element input (this will be time varying (and that's why I thought of a FOR loop!) but for initial development/testing purposes I have used a constant [1 3 6]) and In2 is a constant matrix of 6x3 size whose value is X =

 1     4     6
 1     4     5
 1     3     6
 0     0     0
 2     3     5
 3     5     7

The Simulink model should output the corresponding index (1 based index) of [1 3 6] in X (which should be 3). When I simulate this model I am able to see value '3' at every loop (10 ms loop) inside the FOR loop. But when I see the output (outside the FOR subsystem), it always displays '0' and never equal to '3'. I am not able understand this behavior. Please help!

Upvotes: 0

Views: 2863

Answers (1)

Elie Génard
Elie Génard

Reputation: 1683

The for loop doesn't iterate with the same sample time as your Simulink model. All the iterations occur during a single sample time. I think that's why you always get '3', because it's the result of the last iteration of the for loop. Maybe you could use a selector block to do what you need.

Upvotes: 1

Related Questions