Hi Just wonder if there is an easy and quick way to sort a vector with its corresponding values. for example, I have a vector 'values' and a cell array 'names'. These values are in pairs, so Amy links to 0, Emma links to 4 etc. values = [0, 4, 5, 1, 2] names = {"Amy","Emma","David","Joe","Kate"} If I sort by values, I want to output to be
values = [0, 1, 2, 4, 5] names = {"Amy","Joe","Kate","Emma","David"}
Is there an easy way to do this in matlab?

 採用された回答

dpb
dpb 2016 年 4 月 19 日

0 投票

Use the optional second output from sort and arrange the names array using it...
[values,isort]=sort(values);
names=names(isort);
See
doc sort % for details...

1 件のコメント

wei
wei 2016 年 4 月 19 日
thanks for the fast and brilliant answer

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

wei
2016 年 4 月 19 日

コメント済み:

wei
2016 年 4 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by