[4f740a]: / Supporting Functions / CRI_ShannonEntropy.m

Download this file

13 lines (10 with data), 462 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function [ H, prob ] = CRI_ShannonEntropy(x, bin_min, bin_max, binWidth)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
[counts,binCenters] = hist(x,[bin_min:binWidth:bin_max]);
binWidth = diff(binCenters);
binWidth = [binWidth(end),binWidth]; % Replicate last bin width for first, which is indeterminate.
nz = counts>0; % Index to non-zero bins
prob = counts(nz)/sum(counts(nz));
H = -sum(prob.*log2(prob./binWidth(nz)));
end