Is NaN ok here?
Show older comments
%coin txt
5.00000000e-01 5.00000000e-01
%crime txt
1.66000000e-01 6.60000000e-02 1.40000000e-02 3.90000000e-02 1.40000000e-02 2.70000000e-02 7.20000000e-02 1.00000000e-03 9.00000000e-03 1.30000000e-02 5.50000000e-02 9.00000000e-03 2.80000000e-02 3.80000000e-02 2.60000000e-02 5.50000000e-02 9.60000000e-02 2.30000000e-02 3.50000000e-02 4.50000000e-02 5.40000000e-02 2.40000000e-02 1.00000000e-03 7.00000000e-03 2.00000000e-03 1.50000000e-02 7.00000000e-03 3.00000000e-03 0.00000000e+00 1.40000000e-02 1.80000000e-02 3.00000000e-03 5.00000000e-03 1.80000000e-02
%unfair.txt
9.99000000e-01 1.00000000e-03
%ventsel.txt
1.45000000e-01 6.40000000e-02 1.50000000e-02 3.90000000e-02 1.40000000e-02 2.60000000e-02 7.40000000e-02 8.00000000e-03 1.50000000e-02 6.40000000e-02 1.00000000e-02 2.90000000e-02 3.60000000e-02 2.60000000e-02 5.60000000e-02 9.50000000e-02 2.40000000e-02 4.10000000e-02 4.70000000e-02 5.60000000e-02 2.10000000e-02 2.00000000e-03 9.00000000e-03 4.00000000e-03 1.30000000e-02 6.00000000e-03 3.00000000e-03 1.50000000e-02 1.60000000e-02 3.00000000e-03 7.00000000e-03 1.90000000e-02
%ralph.txt
3.36184163e-02 1.43227594e-01 1.64970470e-01 1.34046838e-01 7.52792246e-02 6.54570283e-02 5.34771727e-03 9.39337045e-02 1.06252105e-01 1.77866902e-01
%ALPH_ENTROPY FUNCTION
function h = alph_entropy(P)
h = sum(-P .* log2(P));
end
%APLH_REDUNDANCY FUNCTION
function r = alph_redundancy(P)
r = sum(1 - (alph_entropy(P)./log2(P)));
end
%main.m
A = load("coin.txt",'-ascii')
B = load("crime.txt",'-ascii')
C = load("unfair.txt",'-ascii')
D = load("ventsel.txt",'-ascii')
E = load("ralph.txt",'-ascii')
Z = [alph_entropy(A) alph_redundancy(A); alph_entropy(B) alph_redundancy(B) ; alph_entropy(C) alph_redundancy(C); alph_entropy(D) alph_redundancy(D); alph_entropy(E) alph_redundancy(E)];
save results.txt Z -ascii;
MATRIX RESULT
%results.txt
1.00000000e+00 4.00000000e+00
NaN NaN
1.14077577e-02 9.90444552e+00
4.41966505e+00 5.87982853e+01
3.06961940e+00 1.90521746e+01
Accepted Answer
More Answers (1)
KSSV
on 20 Nov 2020
0 votes
You have alph_entropy output as 1. log2(1) will be zero and when it is divided i.e. when it is denominator; you will get NaN.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!