It would be something like (provide your own functions for f, and set up the values of M and N),
clc;clear;close;
M=...
function f=functionF(x,y)
end
Pij_single=zeros(M,N); P_of_J=zeros(1,M);
for i=1:M
for j=1:N
Pij_single(i,j)=functionF(i,j);
end
P_of_J(i)=sum(Pij_single(i,:));
end
Pij_sumOnly=sum(P_of_J);
for i=1:M
for j=1:M
P(i,j)=functionF(i,j)./Pij_sumOnly;
end
end
clear P_single, P_of_J;
H_of_J=zeros(1,M);Hij=zeros(N,M);
H=entropy(Pij);
disp('H is: '); H
for i=1:M;
for j=1:N
Hij(i,j)=P(i,j).*log2(P(i,j));
end
H_of_J(i)=sum(Hij(:,1));
end
H=-sum(H_of_J);
disp('H is: '); H
Best Answer