How to sort a table or Excel file (.xlsx) (.csv) and sort the labels correspondingly?
14 ビュー (過去 30 日間)
古いコメントを表示
Dear scholars,
I was wondering how to wrtie a code in MATLAB so sort a table based on the magnitude if numbers and then sort/move the corresponding labels as well?
I mean: suppose: a = 1; b= 2; c=3
I nead a table in this format:
a 1
b 3
c 2
Then I need to sort such a table in an ascending fashion in which sorts the labels (a, b, c) as well. The final answer should be:
a 1
c 2
b 3
Any ideas?
0 件のコメント
回答 (1 件)
Cris LaPierre
2021 年 4 月 8 日
name = ["a";"b";"c"];
val = [1;3;2];
T = table(name,val)
Tsort = sortrows(T,'val')
0 件のコメント
参考
カテゴリ
Help Center および 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!