Re-arrange cell accordingly to a sorted vector

2 ビュー (過去 30 日間)
Guilherme Theis
Guilherme Theis 2020 年 5 月 20 日
コメント済み: Guilherme Theis 2020 年 5 月 20 日
Hello,
I am using a bar plot to showcase values from references, so the X axis has no relevance. However I calculate in a non-sorted way the Y value and I get also a cell that references this Y values. So I would like to first sort Y and then sort the legend cell to be sorted in the same way. For example I have this as output
Y =
3 7 1 2
legend =
1×4 cell array
{'legend1'} {'legend2'} {'legend3'} {'legend4'}
Now I want Y to become Y = 1 2 3 7 and the legends to follow such as in:
newY = sort(Y)
newY =
1 2 3 7
newLegend = sort(legend)
newLegend =
1×4 cell array
{'legend3'} {'legend4'} {'legend1'} {'legend2'}
How can I do this? I am using R2020a

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 5 月 20 日
編集済み: Fangjun Jiang 2020 年 5 月 20 日
utilizde another output of sort(). Note legend() is a function.
[newY, index]=sort(Y)
newLegend=oldLegend(index)
  1 件のコメント
Guilherme Theis
Guilherme Theis 2020 年 5 月 20 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by