pyp = histogram(y,bins);
py = pyp.Values/length;
hy = - sum(py .* log(py+1e-8));
matlab 绘制2d的直方图
pxyp = histogram2(x,y,bins); pxy = pxyp.Values/length; hxy = - sum(sum(pxy .* log(pxy+1e-8)));
%% 计算互信息的函数 function ixy = calMIMatlab(x,y) length = size(x,2); bins = 100 ; pxp = histogram(x, bins); px = pxp.Values/length; hx = - sum(px .* log(px+1e-8)); pyp = histogram(y,bins); py1 = pyp.Values/length; hy = - sum(py1 .* log(py1+1e-8)); pxyp = histogram2(x,y,bins); pxy = pxyp.Values/length; hxy = - sum(sum(pxy .* log(pxy+1e-8))); ixy = hx + hy - hxy; end