NaN+double~=NaN
5 ビュー (過去 30 日間)
古いコメントを表示
Hi! Is it possible to make NaN+double~=NaN instead of NaN+double=NaN? Johan
0 件のコメント
採用された回答
Andrei Bobrov
2012 年 6 月 14 日
eg
A = [nan 2 3 5 nan]
p = 5
out1 = A + p
way without NaN
A2 = A
A2(isnan(A2)) = 0
out2 = A2 + p
0 件のコメント
その他の回答 (1 件)
Walter Roberson
2012 年 6 月 14 日
Well, technically speaking, there are 2^52 different NaN values, half of which (2^51) can be stored like NaN, and (with some effort) distinguished between. MATLAB tends to be careless about the different NaN values, tending to convert them to its one usual NaN, but you can work with them if you are careful.
Somehow I don't think this is what you are looking for, though.
If you want NaN+double to be the double, then don't do the addition operation: check for NaN first and code the result you want.
There is no way in MATLAB to tell MATLAB to handle NaN any differently than it already does. The result of operating on NaN is defined by the IEEE 754 standards on floating point numbers, and is built right in to the CPU.
2 件のコメント
Jan
2012 年 6 月 14 日
The IEEE 754 handling of signaling or non-signaling NaNs is well established.
I would not invent new conventions for the NaN arithmetics, but catch the actual problem by another mechanism like a LOGICAL vector, which caries the information about the validity of the values. Therefore I agree with Walter. +1
Walter Roberson
2017 年 1 月 6 日
You could consider nansum() which is also https://www.mathworks.com/help/finance/nansum.html. Also, in a recent release there is sum(X, 'omitnan')
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!