- 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
46 views (last 30 days)
Show older comments
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 Comment
Stephen23
on 8 Feb 2016
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:
Answers (1)
Walter Roberson
on 8 Feb 2016
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 Comments
Walter Roberson
on 8 Feb 2016
Would you consider showing us the code instead of vaguely describing it?
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!