MATLAB: How to write a function which gives me entropy using discrete probability distribution as input.thanks in advance entropy here is the entropy Formula for discrete probability distribution Best Answer entropy = @(P) -sum(P.*log2(P)) Related SolutionsMATLAB: How i can plot the entropy function H(p1,p2,p3) for three vector of probability p1, p2 and p3= (1-p1-p2) Your formula does not include the term -(1-P_0-P_1).*log2((1-P_0-P_1)), For 2D case, you can get something similar using this.clear allclcp_0=0:0.01:1;p_1=0:0.01:1;[P_0,P_1] = meshgrid(p_0,p_1);H = -P_0.*log2(P_0)-(P_1).*log2(P_1);contour(P_0,P_1, H, 'ShowText', 'on') MATLAB: Different answer using inbuilt function and own code for entropy Simply edit entropy.m and you'll see exactly how they do it:% calculate histogram countsp = imhist(I(:));% remove zero entries in p p(p==0) = [];% normalize p so that sum(p) is one.p = p ./ numel(I);E = -sum(p.*log2(p)); Related QuestionHi, please I want to calculate the distance between this tow matrix using pdist2Estimation/measure of entropyApproximate Entropy Calculation for an Image
Best Answer