samer@39: function y=groupby_ord(f,x) samer@39: % groupby_ord - collect rows of x into equivalence classes based f samer@4: % samer@39: % groupby_ord :: ([[1,M]]->A), [[N,M]] -> {[K]->[[L,M]]} :- equality(A). samer@4: % samer@4: % IMPORTANT: this version assumes that data is ordered by f, that is, samer@4: % only consecutive rows will be grouped together. samer@4: samer@4: N=size(x,1); samer@4: y={}; samer@4: samer@4: i=1; j=1; samer@4: while j<=N samer@4: if i==j, z=f(x(i,:)); end samer@37: if j==N || any(f(x(j+1,:))~=z) samer@4: y=vertcat(y,{x(i:j,:)}); samer@4: i=j+1; j=i; samer@4: else j=j+1; samer@4: end samer@4: end samer@4: