matlab - count equal adjacent element of array -


this question has answer here:

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

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -