Find below a solution, may be not the best one
[c,k]=gsort(c,'r','i'); i=find(c(1:$-1,1)<>c(2:$,1)); r=[];l=1; for j=[i(1:$),size(c,1)] r=[r;c(j,1),sum(c(l:j,2))]; l=j+1; end