mat2str() on complex values with 0 inaginary part
Show older comments
Hi,
Tried mat2str(complex(5,6)) witch seems ok:
ans =
'5+6i'
But other complex values with imaginary part 0 or 0+0i are printed as real values:
mat2str(complex(5,0))
ans =
'5'
mat2str(0+0i)
Seems incorect to me, is this a bug ?
Accepted Answer
More Answers (2)
Firan Lucian
on 26 Jan 2021
Not a bug. Many operations in MATLAB, if the result has an all zero imaginary part, will remove that imaginary part. complex is one of the few operations that does not by design.
x = complex(5, 0)
y = x(1)
z = x + 0
1 Comment
Firan Lucian
on 26 Jan 2021
Categories
Find more on Data Type Identification 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!