I have a column vector with the following sequences:
x = [0,0,1,1,1,2,0,1,2,2,3,3,3,3,3,0,0,0]';
I would like a logical vector a, equalizing 1 if it is equal to the first maximum value of the particular sequence of consecutive numbers (the sequences are separated by zeros), ie:
x = [0,0,1,1,1,2,0,1,2,2,3,3,3,3,3,0,0,0]'; a = [0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0]';
The code should be as efficient as possible (No loops).
Best Answer