function y=entropy(x) % Usage: y=entropy(x) % compute the entropy of a probability vector x % each element of x must be non-negative, and sum(x)=1 % (C) 2006 by Yu Hen Hu % created: Dec. 19. 2006 if min(x) < 0, error('x must contain non-negative entries only!'); end % normalize x such that sum(x)=1 x=x/sum(x); y=-sum(x.*log2(x));