round function on complex numbers
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Stephen23
il 30 Apr 2019
Modificato: Stephen23
il 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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!