log2(0)=-inf problem

5 Ansichten (letzte 30 Tage)
Nikolaos
Nikolaos am 5 Okt. 2011
Hallo,
my problem is that i want to set the quantity log2(0), so as log2(0)==0 {normally it is log2(0)==-inf}. is there a simple way to do this?
Thanks you in advance.

Antworten (1)

Sean de Wolski
Sean de Wolski am 5 Okt. 2011
Write your own log2 and call it:
function out = mylog2(in)
out = log2(in);
out(~in) = 0;
end
Add the F/E output options if desired.
It would be very dangerous to overload this function since it's probably used elsewhere.
  4 Kommentare
Matt Tearle
Matt Tearle am 5 Okt. 2011
y(isinf(y)&~isinf(x)) = 0
Sean de Wolski
Sean de Wolski am 5 Okt. 2011
I'm holding to ~x, logical and foolproof, no, doh! can't convert nan to logical arghh...
x==0

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating Custom Components and Libraries finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by