Mercurial > hg > ishara
view 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 |
line wrap: on
line source
function y=groupby_ord(f,x) % groupby_ord - collect rows of x into equivalence classes based f % % groupby_ord :: ([[1,M]]->A), [[N,M]] -> {[K]->[[L,M]]} :- equality(A). % % IMPORTANT: this version assumes that data is ordered by f, that is, % only consecutive rows will be grouped together. N=size(x,1); y={}; i=1; j=1; while j<=N if i==j, z=f(x(i,:)); end if j==N || any(f(x(j+1,:))~=z) y=vertcat(y,{x(i:j,:)}); i=j+1; j=i; else j=j+1; end end