why is 1+ nan*1i = NaN + NaNi ?
Show older comments
Dear all,
I am trying to figure out how to store some information using complex numbers and retrieving that information later on.
For an operation like
1+nan*1i,
I would like to be able to retrieve "1" by doing
real(1+nan*1i)
and retrieve "nan" by doing
imag(1+nan*1i).
The first case does not work because matlab stores 1+ nan*1i as NaN + NaNi. Is there any workaround to this?
Thanks
Accepted Answer
More Answers (1)
Walter Roberson
on 27 Nov 2015
A = complex(1,nan)
real(A), imag(A)
B = A
However if you were to do
2*A
then you would get complex(NaN, NaN). You can use complex() to force unusual structures such as complex(5,0) but any arithmetic on it is going to demote it to complex(NaN, NaN)
1 Comment
Patrick Mboma
on 28 Nov 2015
Categories
Find more on Descriptive Statistics 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!