Remove Terms in Complex Valued Data That Has Only Real or Imaginary Part

12 ビュー (過去 30 日間)
MarshallSc
MarshallSc 2022 年 6 月 13 日
コメント済み: Voss 2022 年 6 月 13 日
I have a complex numeric array (file attached) that some of its terms have only real or imaginary part, and the rest have both the real and imaginary part. How can I remove the terms in the array that has only one term (real or imaginary) so that the terms that has both real and imaginary are left in the array? For example, for the first 8 rows of the data, I want to remove the first 7 terms:
0.000 + 0.254i
0.000 + 0.317i
0.000 + 0.298i
-0.0467 + 0.000i
0.000 + 0.317i
0.000 + 0.401i
0.000 + 0.437i
-0.0453 + 0.0029i % only this term is needed
Thank you!

採用された回答

Voss
Voss 2022 年 6 月 13 日
編集済み: Voss 2022 年 6 月 13 日
load LR
disp(LR);
0.0000 + 0.2545i 0.0000 + 0.3173i 0.0000 + 0.2984i -0.0468 + 0.0000i 0.0000 + 0.3173i 0.0000 + 0.4014i 0.0000 + 0.4377i -0.0454 + 0.0029i 0.0000 + 0.2984i 0.0000 + 0.4377i -0.1659 + 1.8998i -0.0399 + 0.0053i -0.0468 + 0.0000i -0.0454 + 0.0029i -0.0399 + 0.0053i -0.0347 + 0.0000i 0.0000 + 0.3649i 0.0000 + 0.6330i 0.0000 + 0.3457i -0.0406 + 0.0000i 0.0000 + 0.6330i 0.0000 + 1.5188i 0.0000 + 0.4850i -0.0389 + 0.0000i 0.0000 + 0.3457i 0.0000 + 0.4850i -0.2540 + 1.6553i 0.0000 + 0.0856i -0.0406 + 0.0000i -0.0389 + 0.0000i 0.0000 + 0.0856i -0.0641 + 0.0000i -0.2924 + 0.0069i -0.2233 + 0.0000i -0.2486 + 0.0000i -0.0379 + 0.0000i -0.2233 + 0.0000i -0.2693 + 0.0000i -0.2948 + 0.0000i -0.2597 + 0.0000i -0.2486 + 0.0000i -0.2948 + 0.0000i -24.8645 + 0.0000i -0.0337 + 0.0000i -0.0379 + 0.0000i -0.2597 + 0.0000i -0.0337 + 0.0000i -0.0339 + 0.0000i -0.0140 + 0.0000i -0.0133 + 0.0000i 0.0000 + 0.0057i -0.0359 + 0.0000i -0.0133 + 0.0000i -0.0529 + 0.0000i -0.0624 + 0.0000i -0.0359 + 0.0000i 0.0000 + 0.0057i -0.0624 + 0.0000i -0.0346 + 0.1377i -0.0336 + 0.0000i -0.0359 + 0.0000i -0.0359 + 0.0000i -0.0336 + 0.0000i -0.0339 + 0.0000i
One way:
% remove elements of LR whose real part is 0 or imaginary part is 0
LR(real(LR) == 0 | imag(LR) == 0) = [];
disp(LR);
-0.0454 + 0.0029i -0.1659 + 1.8998i -0.0399 + 0.0053i -0.0454 + 0.0029i -0.0399 + 0.0053i -0.2540 + 1.6553i -0.2924 + 0.0069i -0.0346 + 0.1377i
Another way:
load LR
% keep elements of LR whose real part is non-zero and imaginary part is non-zero
LR = LR(real(LR) ~= 0 & imag(LR) ~= 0);
disp(LR)
-0.0454 + 0.0029i -0.1659 + 1.8998i -0.0399 + 0.0053i -0.0454 + 0.0029i -0.0399 + 0.0053i -0.2540 + 1.6553i -0.2924 + 0.0069i -0.0346 + 0.1377i
load LR
% same but more concise:
LR = LR(real(LR) & imag(LR));
disp(LR)
-0.0454 + 0.0029i -0.1659 + 1.8998i -0.0399 + 0.0053i -0.0454 + 0.0029i -0.0399 + 0.0053i -0.2540 + 1.6553i -0.2924 + 0.0069i -0.0346 + 0.1377i
  2 件のコメント
MarshallSc
MarshallSc 2022 年 6 月 13 日
Thanks a lot mate!
Voss
Voss 2022 年 6 月 13 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by