Sorting a table in Matlab

21 ビュー (過去 30 日間)
Minjun Seo
Minjun Seo 2019 年 8 月 23 日
回答済み: David K. 2019 年 8 月 23 日
I have a table of values that are either string or doubles. I want to sort them alphabetically for strings or least to greatest for numbers. Is there a way that involves not converting the table to a matrix? If there isn't how would I go by converting the table into a matrix and to a table again?

採用された回答

David K.
David K. 2019 年 8 月 23 日
Yes, you can do it with the sortrows function. Here is an example:
A = [1 2 4 5 3 6 5 6];
B = {'a', 'b', 'c', 'e', 'f', 'ba', 'bd' , 'bc'};
tab = table(A',B');
% Sort by doubles
Output = sortrows(tab,1)
% Sort by string
Output = sortrows(tab,2)

その他の回答 (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