Sorting cell arrays with characters and numbers
조회 수: 9 (최근 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!