Is there a method to sort a list an array of words alphabetically (natural order sorting)

조회 수: 125 (최근 30일)
Hi, I was wondering if there is any method to sort the words alphabetically. I know how it can be done in Java, but I assusme Matlab should be having a quicker and compact method.
Cheers, Vish

채택된 답변

David Young
David Young 2011년 2월 6일
>> sort({'gamma', 'delta', 'alpha', 'beta'})
ans =
'alpha' 'beta' 'delta' 'gamma'

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 2월 6일
There is no single "natural order" for sorting. The rules for sorting alphabetically depend upon language and region. Especially if the language has accents or other diacritical marks.
If you were to specify exactly which characters you wish to deal with and the exact sorting order, someone might be able to assist you.
There is no Mathworks provided function that uses the LOCALE information to determine how to sort, and there is no Mathworks provided "dictionary sort" routine even just for English.
  댓글 수: 6
Walter Roberson
Walter Roberson 2011년 2월 6일
이동: DGM 2023년 3월 9일
"Expert", definition: someone who tells you all the ways that something cannot be done.
Marie Trang
Marie Trang 2023년 3월 9일
이동: DGM 2023년 3월 9일
I know this is an older thread, but to help anyone looking at this, I used the sortrows() command for my 7x7 character array and it worked fine to organize them alphabetically in terms of the english alphabet. I found that sort() works to organize cell arrays of strings or characters alphabetically, so it's up to you whether to use sortrows() or sort() based on if you're working with a string/character array or a cell array of strings/characters. Hope this helps!

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by