I am a new user of MatLab and I am stuck with a simple task. I have an array made of 0s and 1s: I need to check if 1s occur more than X time consecutively. i.e. A = [ 0 1 1 1 0 1 0 1 1 1 1 0 1] and I need to know if I have 4 (for example) consecutive 1s in the array ( it only needs to happen once for me to go on with what I am trying to do). If the condition is verified I will then create a new variable, e.g. Y, and set equal to 1 and continue with my script.
Thank you for the help
This should do the job: The while loop cuts a vector with 4 elements from the array and compares it to a vector with 4 elements and only ones. If a vector of 4 consecutive ones is contained in A, the variable four_consecutive_ones_found will be set to 1, otherwise it will return 0.