round function on complex numbers
16 views (last 30 days)
Show older comments
So I have entered a complex array like this
a = [1,1,1,1; 1 -j -1 -1; 1 -1 1 -1; 1 j -1 -j]
And get output as
a =
1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i
1.0000 + 0.0000i 0.0000 - 1.0000i -1.0000 + 0.0000i -1.0000 + 0.0000i
1.0000 + 0.0000i -1.0000 + 0.0000i 1.0000 + 0.0000i -1.0000 + 0.0000i
1.0000 + 0.0000i 0.0000 + 1.0000i -1.0000 + 0.0000i 0.0000 - 1.0000i
which is fine.
But I want to round this array to show complex numbers as integers. Eg 1 + 0i, 1+ i etc. How do I achieve this?
round() function doesnt seem to do anything as
>> round(a)
ans =
1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i
1.0000 + 0.0000i 0.0000 - 1.0000i -1.0000 + 0.0000i -1.0000 + 0.0000i
1.0000 + 0.0000i -1.0000 + 0.0000i 1.0000 + 0.0000i -1.0000 + 0.0000i
1.0000 + 0.0000i 0.0000 + 1.0000i -1.0000 + 0.0000i 0.0000 - 1.0000i
0 Comments
Answers (1)
Stephen23
on 30 Apr 2019
Edited: Stephen23
on 30 Apr 2019
>> format short g
>> a = [1,1,1,1; 1 -j -1 -1; 1 -1 1 -1; 1 j -1 -j]
a =
1 1 1 1
1 0 - 1i -1 -1
1 -1 1 -1
1 0 + 1i -1 0 - 1i
Or write your own display code using fprintf, e.g.:
>> fmt = [repmat(' %d%+di',1,size(a,2)),'\n'];
>> fprintf(fmt,a.')
1+1i 1+1i 1+0i -1-1i
1-1i 1-1i 1+0i -1+0i
0 Comments
See Also
Categories
Find more on Title in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!