round function on complex numbers

조회 수: 2 (최근 30일)
Shashank K Holla
Shashank K Holla 2019년 4월 30일
편집: Stephen23 2019년 4월 30일
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

답변 (1개)

Stephen23
Stephen23 2019년 4월 30일
편집: Stephen23 2019년 4월 30일
This has nothing to do with rounding. Either change the format, e.g.:
>> 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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by