I have two variables
A=[1000 16000 10000 30000 2000]
B=[150 100 4000 5000 2000]
I want to sort Variable B according to A
The 1st minimum of A is 1000 it is in 1syt position and B is 100 so 100 must be in first position
The 2nd minimum of A is 2000 it is in 5th position and B is 150,so 150 must be placed in 5th position ,and so on pleas help
C=[100 4000 2000 5000 150]

 採用された回答

Dishant Arora
Dishant Arora 2012 年 9 月 15 日

0 投票

[~ ~ k]=unique(A);
B=unique(B);
C=B(k);

4 件のコメント

kash
kash 2012 年 9 月 15 日
i get error
Error: An array for multiple LHS assignment cannot contain expressions.
Dishant Arora
Dishant Arora 2012 年 9 月 15 日
[ii jj k]=unique(A);
use this.
kash
kash 2012 年 9 月 15 日
Thanks Dishant can you please tell what values are stored in k,i did not understand that
Dishant Arora
Dishant Arora 2012 年 9 月 15 日
編集済み: Dishant Arora 2012 年 9 月 15 日
doc unique.
and the reason you got the error lies in the link below:
have a look at the answer by jan there.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by