So, I’ve got a 1D matrix of values in MATLAB that will contain the value either 11 or 12.
For example n=[11,12,11,12,12,12,11,11];
I want to pick out values based on the following rules:
-
Any value of 11 must be preceeded by a 12
-
Any value of 12 must be followed by an 11
The format of the output isn’t important. An array that highlights which don’t conform to the above rules such as n1=[0,1,1,0,0,1,1,0]; would do the trick.
How can I do this in a vectorized way?
This code should work:
Basically we are looking at the sequence with preceding number is greater than following by 1.