function [P,C,Err]=lbgUpdate(X,C) % function C=lbgUpdate(X,C) % Performs 1 step of the LBG algorithm where X is p by n (data) % and C is k by n (k clusters) % P holds the sorted data % C is the new matrix of clusters % Err is a vector of distortion errors [m,n]=size(X); [k,p]=size(C); if n~=p error('Data dimensions do not match in lbgUpdate\n'); end D=edm(X,C); Err=sqrt(sum(D.*D,2)); [Vals,Idx]=min(D,[],2); for j=1:k idx=find(Idx==j); if length(idx)>0 P{j}=X(idx,:); C(j,:)=mean(P{j}); end end