MATLAB Answers

conditioning array with complex number

1 view (last 30 days)
JK
JK on 14 Sep 2021
Commented: Star Strider on 14 Sep 2021
I would like to apply a condition to make certain complex numbers to zero.
condition: if complex number * conj(complex number) is less than 0.5, set complex number to zero.
I tried A(A.*conj(A)<0.5)=0. it didn't work out.

Accepted Answer

Star Strider
Star Strider on 14 Sep 2021
This can probably be combined into fewer actual lines. I kept them separate to demonstrate the approach —
A = complex(rand(10),rand(10))
A =
0.3470 + 0.8859i 0.0137 + 0.7639i 0.1015 + 0.7223i 0.5190 + 0.9946i 0.2642 + 0.9262i 0.1227 + 0.4625i 0.5610 + 0.0151i 0.9365 + 0.1072i 0.9752 + 0.7804i 0.8272 + 0.9432i 0.4636 + 0.2904i 0.1338 + 0.2256i 0.3974 + 0.6367i 0.9876 + 0.3169i 0.2435 + 0.0412i 0.3481 + 0.5287i 0.9613 + 0.8060i 0.3516 + 0.6644i 0.7104 + 0.0387i 0.1082 + 0.4680i 0.0129 + 0.6059i 0.0952 + 0.5557i 0.5719 + 0.9788i 0.2254 + 0.7534i 0.8180 + 0.1280i 0.5472 + 0.2541i 0.8326 + 0.8705i 0.0095 + 0.3066i 0.3927 + 0.4640i 0.7428 + 0.6265i 0.7454 + 0.4747i 0.4278 + 0.9148i 0.8096 + 0.6022i 0.7720 + 0.5985i 0.2754 + 0.3324i 0.9874 + 0.6228i 0.5922 + 0.1384i 0.9802 + 0.0692i 0.6346 + 0.6318i 0.1758 + 0.3041i 0.6405 + 0.2935i 0.5829 + 0.1763i 0.2208 + 0.8402i 0.5265 + 0.3813i 0.8351 + 0.2082i 0.9958 + 0.7694i 0.3690 + 0.7676i 0.6434 + 0.2222i 0.0020 + 0.1934i 0.6156 + 0.8573i 0.0943 + 0.9701i 0.3803 + 0.4209i 0.1179 + 0.9497i 0.9916 + 0.6548i 0.2876 + 0.1710i 0.0866 + 0.8797i 0.3089 + 0.4247i 0.3803 + 0.3770i 0.7961 + 0.3813i 0.2586 + 0.0791i 0.5874 + 0.2785i 0.2163 + 0.3044i 0.2791 + 0.4933i 0.2559 + 0.8200i 0.8186 + 0.4434i 0.2505 + 0.6017i 0.5400 + 0.9447i 0.1880 + 0.5847i 0.6254 + 0.6406i 0.3905 + 0.6088i 0.3084 + 0.0559i 0.5232 + 0.9541i 0.1421 + 0.3563i 0.6262 + 0.1674i 0.8474 + 0.7592i 0.1504 + 0.9597i 0.8628 + 0.9455i 0.9468 + 0.2465i 0.5404 + 0.7113i 0.6113 + 0.0233i 0.2909 + 0.3973i 0.9900 + 0.4806i 0.3832 + 0.9495i 0.3579 + 0.1691i 0.1201 + 0.1768i 0.3424 + 0.0581i 0.0161 + 0.4895i 0.9649 + 0.5228i 0.0355 + 0.1678i 0.8364 + 0.5422i 0.1649 + 0.9458i 0.4645 + 0.4179i 0.3430 + 0.6006i 0.5904 + 0.2400i 0.2482 + 0.3173i 0.3150 + 0.9556i 0.7045 + 0.5468i 0.8496 + 0.4076i 0.4556 + 0.8503i 0.0623 + 0.0865i
A2 = A.*conj(A)
A2 = 10×10
0.9052 0.5838 0.5320 1.2586 0.9276 0.2290 0.3150 0.8886 1.5600 1.5739 0.2992 0.0688 0.5634 1.0759 0.0610 0.4007 1.5737 0.5651 0.5061 0.2308 0.3672 0.3178 1.2851 0.6184 0.6855 0.3640 1.4510 0.0941 0.3695 0.9442 0.7809 1.0198 1.0182 0.9541 0.1864 1.3628 0.3699 0.9656 0.8019 0.1234 0.4964 0.3708 0.7546 0.4226 0.7408 1.5837 0.7253 0.4634 0.0374 1.1140 0.9499 0.3218 0.9158 1.4120 0.1120 0.7814 0.2758 0.2868 0.7791 0.0731 0.4225 0.1395 0.3212 0.7379 0.8667 0.4248 1.1840 0.3773 0.8014 0.5231 0.0983 1.1840 0.1471 0.4201 1.2945 0.9436 1.6383 0.9573 0.7979 0.3742 0.2425 1.2111 1.0484 0.1567 0.0457 0.1206 0.2399 1.2044 0.0294 0.9935 0.9217 0.3904 0.4783 0.4062 0.1622 1.0124 0.7954 0.8880 0.9305 0.0114
idx = A2 < 0.5
idx = 10×10 logical array
0 0 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 0 1 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 0 1 1 0 0 1 0 0 1 0 1 1 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 0 0 0 1
A(idx) = 0
A =
0.3470 + 0.8859i 0.0137 + 0.7639i 0.1015 + 0.7223i 0.5190 + 0.9946i 0.2642 + 0.9262i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.9365 + 0.1072i 0.9752 + 0.7804i 0.8272 + 0.9432i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.3974 + 0.6367i 0.9876 + 0.3169i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.9613 + 0.8060i 0.3516 + 0.6644i 0.7104 + 0.0387i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.5719 + 0.9788i 0.2254 + 0.7534i 0.8180 + 0.1280i 0.0000 + 0.0000i 0.8326 + 0.8705i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.7428 + 0.6265i 0.7454 + 0.4747i 0.4278 + 0.9148i 0.8096 + 0.6022i 0.7720 + 0.5985i 0.0000 + 0.0000i 0.9874 + 0.6228i 0.0000 + 0.0000i 0.9802 + 0.0692i 0.6346 + 0.6318i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.2208 + 0.8402i 0.0000 + 0.0000i 0.8351 + 0.2082i 0.9958 + 0.7694i 0.3690 + 0.7676i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.6156 + 0.8573i 0.0943 + 0.9701i 0.0000 + 0.0000i 0.1179 + 0.9497i 0.9916 + 0.6548i 0.0000 + 0.0000i 0.0866 + 0.8797i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.7961 + 0.3813i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.2559 + 0.8200i 0.8186 + 0.4434i 0.0000 + 0.0000i 0.5400 + 0.9447i 0.0000 + 0.0000i 0.6254 + 0.6406i 0.3905 + 0.6088i 0.0000 + 0.0000i 0.5232 + 0.9541i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.8474 + 0.7592i 0.1504 + 0.9597i 0.8628 + 0.9455i 0.9468 + 0.2465i 0.5404 + 0.7113i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.9900 + 0.4806i 0.3832 + 0.9495i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.9649 + 0.5228i 0.0000 + 0.0000i 0.8364 + 0.5422i 0.1649 + 0.9458i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.3150 + 0.9556i 0.7045 + 0.5468i 0.8496 + 0.4076i 0.4556 + 0.8503i 0.0000 + 0.0000i
Experiment to get different results.
.
  2 Comments
Star Strider
Star Strider on 14 Sep 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!