フィルターのクリア

How to sort dependent vectors?

1 回表示 (過去 30 日間)
Aleksandra Pawlak
Aleksandra Pawlak 2020 年 11 月 29 日
コメント済み: Ameer Hamza 2020 年 11 月 29 日
Hi,
I have two vectors for example:
A=[0 8 2 9 1 10 23]
B=[2 30 23 90 45 47 5]
I need to make chart where B is depending of A ( B=f(A) )
I sorted A vector using:
Asorted = sort(A,'ascend')
How to sort B vector to the elements corresponding to the values of A (before sorting)?
In the end i want to get vectors
Asorted=[0 1 2 8 9 10 23]
Bsorted=[2 45 23 30 47 5]

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 29 日
編集済み: Ameer Hamza 2020 年 11 月 29 日
Second outout if sort() gives the index used to sort the vector. You can use it to arrange element of B.
A=[0 8 2 9 1 10 23];
B=[2 30 23 90 45 47 5];
[Asorted, idx] = sort(A,'ascend')
Bsorted = B(idx)
  4 件のコメント
Aleksandra Pawlak
Aleksandra Pawlak 2020 年 11 月 29 日
I see the problem- i make missprint: ixd instead of idx in [Asorted, idx].
Thank you and sorry for the confusion
Ameer Hamza
Ameer Hamza 2020 年 11 月 29 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by