view general/funutils/groupby.m @ 22:4f5015db91aa

Moved maxnormalise to unitmax
author samer
date Thu, 17 Jan 2013 14:23:21 +0000
parents e44f49929e56
children beb8a3f4a345
line wrap: on
line source
function y=groupby_or(f,x)
% groupby_or - collect rows of x into equivalence classes based f
%
% groupby_or :: ([[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 || f(x(j+1,:)~=z)
			y=vertcat(y,{x(i:j,:)});
			i=j+1; j=i;
		else j=j+1; 
		end
	end