round function on complex numbers
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Stephen23
am 30 Apr. 2019
Bearbeitet: Stephen23
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!