MATLAB: Find all occuarances of two numbers together

strfind

Hi,
I have an array, a = [ 0 -1 1 0 0 -1 1 0]
How can I fing all the ocurances of [ 1 0], ie. the index showing when the number 0 occurs after the number 1.
I want to create, b = [0 0 0 1 0 0 0 0 1].
I'm trying to use teh strfind fuction, but am stuck.
Thank you!
Inna

Best Answer

Try this
a = [ 0 -1 1 0 0 -1 1 0];
idx = strfind(a, [1 0])+1;
b = zeros(size(a));
b(idx) = 1;