Sorting rows - case insensitive?

18 次查看(过去 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