Sorting complex array with cplxpair and how to get the sort index?

7 ビュー (過去 30 日間)
Murthy MVVS
Murthy MVVS 2021 年 5 月 25 日
コメント済み: Murthy MVVS 2021 年 5 月 25 日
I have a vector of complex numbers, which I sort using cplxpair to get the complex conjugates in ordered pair. But now I need to know the index with respect to the orginal vector.
For example,
I have,
k = [
0.0000 - 0.9998i
0.0000 - 0.9995i
0.0000 + 0.9998i
0.0000 + 0.9995i
-0.0001 - 0.9491i
0.0000 + 0.9995i
0.0000 - 0.9995i
-0.0001 + 0.9491i
]
I use cplxpair(k) and I get,
kp = [
-0.0001 - 0.9491i
-0.0001 + 0.9491i
0.0000 - 0.9998i
0.0000 + 0.9998i
0.0000 - 0.9995i
0.0000 + 0.9995i
0.0000 - 0.9995i
0.0000 + 0.9995i
]
But I need to know how to get the index of 'kp' relating to that of 'k'.

採用された回答

Paul
Paul 2021 年 5 月 25 日
編集済み: Paul 2021 年 5 月 25 日
ismember() might be what you're looking for. Do you care about how this works if the elements of k are not all unique?
k = [
0.0000 - 0.9998*1i
0.0000 - 0.9995*1i
0.0000 + 0.9998*1i
0.0000 + 0.9995*1i
-0.0001 - 0.9491*1i
0.0000 + 0.9995*1i
0.0000 - 0.9995*1i
-0.0001 + 0.9491*1i];
kp = cplxpair(k);
[~,ind] = ismember(k,kp);
[kp(ind) k]
ans =
0.0000 - 0.9998i 0.0000 - 0.9998i 0.0000 - 0.9995i 0.0000 - 0.9995i 0.0000 + 0.9998i 0.0000 + 0.9998i 0.0000 + 0.9995i 0.0000 + 0.9995i -0.0001 - 0.9491i -0.0001 - 0.9491i 0.0000 + 0.9995i 0.0000 + 0.9995i 0.0000 - 0.9995i 0.0000 - 0.9995i -0.0001 + 0.9491i -0.0001 + 0.9491i
isequal(kp(ind),k)
ans = logical
1
Note that k contained duplicate values, so ind is not just a shuffle of 1:8
sort(ind).'
ans = 1×8
1 2 3 4 5 5 6 6

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by