function H = entropy(p) N = length(p); H=0; for i=1:N if (p(i) > 0) H = H - p(i)* log2(p(i)); end end