Sorting cell arrays with characters and numbers
8 ビュー (過去 30 日間)
古いコメントを表示
Given a cell array such as {'a1', 'a2', 'a3'...'a9', 'a10', 'a11','a12'}, in random order ofcourse, using the sort function gives me {'a1', 'a10', 'a11','a12','a1','a2',...'a9'}. What method can be used to get the right order?
0 件のコメント
採用された回答
Stephen23
2022 年 10 月 30 日
編集済み: Stephen23
2022 年 10 月 30 日
"What method can be used to get the right order?"
You could download my FEX submission NATSORT:
unzip it onto your MATLAB search path or into the current directory, then call it like this:
C = {'a11', 'a9', 'a3', 'a2', 'a12', 'a1','a10'}
D = natsort(C)
2 件のコメント
その他の回答 (1 件)
Walter Roberson
2022 年 10 月 30 日
編集済み: Walter Roberson
2022 年 10 月 30 日
MATLAB already gives the "right" order, just not the order you want.
https://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-order-sort
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!