MATLAB: Finding multiple first or last indicies

findindexing

How can you index the first or last values in a column:
x = [1;1;1;0;0;1;1;0;1;0;0;1]
find the first instances of the 1's: index1=[1,6,9,12]
find the last instances of 0's: index0 = [5,8,11]

Best Answer

x = [1;1;1;0;0;1;1;0;1;0;0;1]
s = [0, x.'];
result1 = strfind(s, [0, 1])
result2 = result1(2:end) - 1