- Any arithmetic operation on a NaN, such as sqrt(NaN)
- Addition or subtraction, such as magnitude subtraction of infinities as (+Inf)+(-Inf)
- Multiplication, such as 0*Inf
- Division, such as 0/0 and Inf/Inf
- Remainder, such as rem(x,y) where y is zero or x is infinity
My final output matrix contains NaN values
21 ビュー (過去 30 日間)
古いコメントを表示
I have written a code where there are 100 iterations, and at the end I get a matrix (14680*101). for some strange reason, some elements of this matrix are NaN. The simulation ran fine, no error message in matlab, and it didn't stop. Does anyone have any idea what this means? an row example: Iteration1.........Iteration 35 Iteration 36.........Iteration 100 Row1: 12.21121...........35.546654799912 NaN ( from this point and on, they are all NaN)
1 件のコメント
Stephen23
2016 年 2 月 8 日
You need to check the calculation. NaN's do not mean "error", they mean that the result of a calculation is not defined. Check for divide-by-zero, multiply by infinity, etc. The nan documentation lists all of the things you need to check for:
回答 (1 件)
Walter Roberson
2016 年 2 月 8 日
We need to see the code.
If you have a loop in which one iteration depends on the previous value then it is almost certain that as soon as one Nan is produced that everything else will be nan.
You get nan from 0/0 or 0*infinity. Do you have log of an exponential value? Too large of an exponent would lead to infinity and log cannot recover the original exponent when that happens.
2 件のコメント
Walter Roberson
2016 年 2 月 8 日
Would you consider showing us the code instead of vaguely describing it?
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!