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

1 view (last 30 days)
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?

Accepted Answer

Stephen23
Stephen23 on 14 Aug 2018
Edited: Stephen23 on 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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!