필터 지우기
필터 지우기

Help with Sorting cell

조회 수: 2 (최근 30일)
sc1991
sc1991 2018년 1월 4일
댓글: Stephen23 2018년 1월 4일
Hi i have the following cell test
'Apr1'
'Apr10'
'Apr11'
'Apr12'
'Apr13'
'Apr14'
'Apr15'
'Apr17'
'Apr18'
'Apr19'
'Apr20'
'Apr21'
'Apr22'
'Apr23'
'Apr24'
'Apr25'
'Apr29'
'Apr30'
'Apr8'
'Apr9'
can someone tell me how to sort it so that I get the following result
'Apr1'
'Apr8'
'Apr9'
'Apr10'
'Apr11'
'Apr12'
'Apr13'
'Apr14'
'Apr15'
'Apr17'
'Apr18'
'Apr19'
'Apr20'
'Apr21'
'Apr22'
'Apr23'
'Apr24'
'Apr25'
'Apr29'
'Apr30'

채택된 답변

Stephen23
Stephen23 2018년 1월 4일
편집: Stephen23 2018년 1월 4일
Download my FEX submission natsort, and simply use it like this:
test = natsort(test)
where test is your cell array. You might also be interested in natsortfiles, which is written specifically for sorting filenames and path names.
  댓글 수: 3
Jan
Jan 2018년 1월 4일
+1. This is a smart and nice solution. It would be even nicer to avoid the problem by using 'Apr01' instead of 'Apr1': Then sort is sufficient. But this was not part of the question.
Stephen23
Stephen23 2018년 1월 4일
"It would be even nicer to avoid the problem by using 'Apr01' instead of 'Apr1': Then sort is sufficient"
Correct. Using ISO 8601 date formats also has the same advantage.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by