annotate general/funutils/groupby_ord.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents c388f1c70669
children
rev   line source
samer@39 1 function y=groupby_ord(f,x)
samer@39 2 % groupby_ord - collect rows of x into equivalence classes based f
samer@4 3 %
samer@39 4 % groupby_ord :: ([[1,M]]->A), [[N,M]] -> {[K]->[[L,M]]} :- equality(A).
samer@4 5 %
samer@4 6 % IMPORTANT: this version assumes that data is ordered by f, that is,
samer@4 7 % only consecutive rows will be grouped together.
samer@4 8
samer@4 9 N=size(x,1);
samer@4 10 y={};
samer@4 11
samer@4 12 i=1; j=1;
samer@4 13 while j<=N
samer@4 14 if i==j, z=f(x(i,:)); end
samer@37 15 if j==N || any(f(x(j+1,:))~=z)
samer@4 16 y=vertcat(y,{x(i:j,:)});
samer@4 17 i=j+1; j=i;
samer@4 18 else j=j+1;
samer@4 19 end
samer@4 20 end
samer@4 21