function [B,breakpts] = addcoarsecol (A,C,N) % ADDCOARSECOL coarsens (bins) a column of a matrix. % % B = addcoarsecol (A,C,N) % % B is matrix A with an extra column with % The C-th column of A binned into N bins of similar size. % breakpts is a (N+1)-long row vector with the breakpts of the bins. % % A is a matrix. % Consider the values in column C of A. % We want to split them into N classes of about equal size. % These classes are numbered 1 to N inclusive. % Each point is given a number saying which class it is in. % % E.g. A = [1 2 3 % 1 3 -9 % 2 6 10 % -7 1 0] % % then B = addcoarsecol (A,2,2) gives % % E.g. B = [1 2 3 1 % 1 3 -9 2 % 2 6 10 2 % -7 1 0 1] % ^ % |___ This column got binned into [2,2], [3,6] % % % Dinoj Surendran dinoj@cs.uchicago.edu B = A; [K,L] = size(A); vals = A(:,C); valsorted = sort(vals); breakpts = valsorted([1:N-1]*floor(K/N)); if (size(breakpts,1) > size(breakpts,2)) breakpts = breakpts.'; % breakpts is row vector end breakpts = [min(vals)-1 breakpts max(vals)+1]; for k=1:K b = B(k,C); i = 1; while b > breakpts(i) i = i+1; end B(k,L+1) = i-1; end