MATLAB: The first Position of the same values find

1

Hi, please, how can i find respectively the position of first 3 suppose i have:
A = [3 3 3 3 0 0 3 3 3 3 0 0 0 3 3 3 3 0 3 3 3 3];
[pks,locs]= find(A==3); % but only each first position of 3
Thanks to the person who can help me 🙂

Best Answer

A = [3 3 3 3 0 0 3 3 3 3 0 0 0 3 3 3 3 0 3 3 3 3];
loc = find(A == 3);
startruns = loc(find(diff([-1 loc]) > 1)) %-1 could be any value less than 0