필터 지우기
필터 지우기

Sorting rows - case insensitive?

조회 수: 17 (최근 30일)
Maroulator
Maroulator 2014년 11월 13일
답변: Guillaume 2014년 11월 13일
I am trying to sort the following matrix in alphabetical order and sortrows(A) seems to do the trick, except for the fact that the word "Happy" doesn't get properly sorted. Is there a way to make sortrows case insensitive, or accomplish my objective with a different function that is flexible enough to accommodate an option for case insensitivity?
Thanks in advance.
A=[Happy the man and happy he alone]
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 13일
편집: Azzi Abdelmalek 2014년 11월 13일
Your question is not clear, and the variable A=[Happy the man and happy he alone] does not make sens, maybe
A='Happy the man and happy he alone'
Or
A={'Happy' 'the' 'man' 'and' 'happy' 'he' 'alone'}

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 13일
편집: Azzi Abdelmalek 2014년 11월 13일
A={'Happy' 'the' 'man' 'and' 'happy' 'he' 'alone'}
[~,idx]=sort(upper(A))
out=A(idx)

Guillaume
Guillaume 2014년 11월 13일
There is no case insensitive sorting function in matlab. However, you can always convert your string(s) to all upper or lower case before the sort with upper or lower.

카테고리

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