log2(0)=-inf problem
显示 更早的评论
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.
回答(1 个)
Sean de Wolski
2011-10-5
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 个评论
Matt Tearle
2011-10-5
Or, post process: y = log2(x); y(isinf(y)) = 0;
Am I suggesting some logical indexing? Why, yes, I think I am!
Sean de Wolski
2011-10-5
x = [0 inf -inf 3];
Matt Tearle
2011-10-5
y(isinf(y)&~isinf(x)) = 0
Sean de Wolski
2011-10-5
I'm holding to ~x, logical and foolproof, no, doh! can't convert nan to logical arghh...
x==0
类别
在 帮助中心 和 File Exchange 中查找有关 Creating Custom Components and Libraries 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!