How do I threshold only real part of a complex matrix?

1 Ansicht (letzte 30 Tage)
D_coder
D_coder am 14 Aug. 2018
Erneut geöffnet: Walter Roberson am 22 Dez. 2018
For a complex matrix how do I threshold only the real part of its elements to zero if I have complex matrix A, A(real(A)>0.5)=0 will make the entire complex matrix elements with real part greater than 0.5 as zero but not specifically the real part. How to do that in a single line?

Akzeptierte Antwort

Stephen23
Stephen23 am 14 Aug. 2018
Bearbeitet: Stephen23 am 14 Aug. 2018
>> A = complex(randi([-3,3],4,4),randi([-3,3],4,4)) % fake data
A =
-2 + 3i -2 + 1i 2 - 3i -2 + 1i
-2 + 0i 3 + 0i -3 + 3i 0 + 0i
2 + 0i 2 - 2i 3 + 3i 0 - 3i
1 - 2i -3 - 2i 3 + 2i 0 - 2i
>> B = complex(real(A).*(real(A)<=0.5),imag(A)) % set real(A)>0.5 to 0.
B =
-2 + 3i -2 + 1i 0 - 3i -2 + 1i
-2 + 0i 0 + 0i -3 + 3i 0 + 0i
0 + 0i 0 - 2i 0 + 3i 0 - 3i
0 - 2i -3 - 2i 0 + 2i 0 - 2i

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by