function h = entropy(x)
x = double(x);                        % Make input double
xh = hist(x(:), min(x(:)):max(x(:)));                   % Compute N-bin histogram
xh = xh / sum(xh(:));                 % Compute probabilities  

% Make mask to eliminate 0's since log2(0) = -inf.
i = find(xh);           

h = -sum(xh(i) .* log2(xh(i)));       % Compute entropy
