matlab - count equal adjacent element of array -
this question has answer here:
- run length encoding in matlab 4 answers
 
i've vector
a = [0;1;1;1;0;0;1;1;1;2;2;2;2];   and want count number of equal adjacent values in order have matrix this:
b=[0 1    1 3    0 2    1 3    2 4];   can me?
here short solution:
j=find(diff([a(1)-1; a])); b=[a(j), diff([j; numel(a)+1])];      
Comments
Post a Comment