How to break FOR loop in simulink

Viewed 108

In Simulink, I have a signal that is a 1-D array.
I want to get the index of the first value other than 0, but the result received is the index of the last non-zero value enter image description here I am new to Simulink, is there any way to break FOR loop?
Or what should I do in this case
Any hint will be great.
Thanks.

1 Answers

Rather than using a for loop iterator subsystem, use the while iterator subsystem.

From the properties you can enable the "Show iteration number port" option to give you the index to increment over the items in the array. The while iterator also has a "cond" or condition input which you can set to exit the while loop when you get to a non-zero value.

Alternatively, use the for loop but work from the end of the array towards the front and output the last non-zero value which will be the first non-zero value if you worked in a forwards direction. Use the length minus the index value to access the array to work backwards.

Related