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

6 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Voss
Voss el 13 de Jun. de 2022
Editada: Voss el 13 de Jun. de 2022
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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by