Tlaloc-ES
Tlaloc-ES

Reputation: 5282

Why does matlab return -Inf with log2 function?

I'm calculating

info = log2(double(1/prob))

in matlab, but when I try to print the result, it show -Inf

prob is a uint8 variable.

how can it fix it?

Upvotes: 1

Views: 181

Answers (1)

fuesika
fuesika

Reputation: 3330

If you divide 1 by another integer, this will surely result in a zero.. putting this into a logarithm yields the observed -Inf... you will need to convert to floating point prior to the division, e.g.

info = log2( 1./double(prob) )

Upvotes: 4

Related Questions