Output only numbers with complex conjugate

Lets say I have an Array
a = [1+i*0.1, 1-i*0.1, 5-i*0.1, 10+i*0.2, 10-i*0.2]
which only contains complex numbers. I would like my output to only contains those numbers which have an corresponding complex conjugate inside the array e.g.
out = [1+i*0.1 10+i*0.2]
The output could also just contain the complex conjugate, but not both
Any help is greatly appreciated.

 採用された回答

Bruno Luong
Bruno Luong 2020 年 11 月 24 日

0 投票

a(ismember(a,conj(a))&imag(a)>=0)

その他の回答 (1 件)

Rik
Rik 2020 年 11 月 24 日

1 投票

a = [1+1i*0.1, 1-1i*0.1, 5-1i*0.1, 10+1i*0.2, 10-1i*0.2];
b=conj(a);
c=b(ismember(b,a));
d=real(c)+1i*abs(imag(c));
e=unique(d)
e = 1×2
1.0000 + 0.1000i 10.0000 + 0.2000i
(the displaying seems to have some issues, but it is indeed the vector you describe)

5 件のコメント

Star Strider
Star Strider 2020 年 11 月 24 日
See if the cplxpair function can help!
Rik
Rik 2020 年 11 月 24 日
Wouldn't that just return an error when used on a? Or do you mean this?
a = [1+1i*0.1, 1-1i*0.1, 5-1i*0.1, 10+1i*0.2, 10-1i*0.2];
b=conj(a);
c=b(ismember(b,a));
d=cplxpair(c);
e=d(2:2:end)
Ko Fa
Ko Fa 2020 年 11 月 24 日
Thank you Rik! This is working perfectly fine.
I was just confused at first, thinking my numbers are getting messed up somehow. I just now realized this is filling "e" in ascending order.
Rik
Rik 2020 年 11 月 24 日
You can also use the 'stable' option in unique if you want to preserve the original order.
Ko Fa
Ko Fa 2020 年 11 月 24 日
True! Thank you.

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

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

質問済み:

2020 年 11 月 24 日

コメント済み:

2020 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by