Sort alphabetically without using sort
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Is it possible to sort alphabetically without using sort? If so, how can be do it?
4 comentarios
the cyclist
el 22 de En. de 2017
Sorry, this is a MATLAB version difference.
'cat' < 'dog'
evaluates letter-by-letter, but
string('cat') < string('dog')
will compare the strings as I suggested, in R2016b.
Respuestas (1)
Walter Roberson
el 21 de En. de 2017
Editada: Walter Roberson
el 22 de En. de 2017
It is not possible to do alphabetic sorts using sort(). There is no human language for which sort() will return alphabetic order.
You can either program everything yourself, or you can use the POSIX standard environment variables LANG, LC_ALL, LC_COLLATE and write a little bit of C or C++ code to call strcoll()
Alphabetic sort is really quite messy to get right. Does uppercase sort before or after lowercase? Do letters with diacritics sort before or after the same letter without diacritics? What do you do about the fact that in some languages, ö is a distinct letter but in other languages it is a letter with a diacritic? What do you do about the fact that ß can be substituted with ss if necessary in print but which must be treated differently from ss for documents that predate the 1996 reform spelling rules? What do you do about hyphens?
Now, how do you sort names? Should "L. Sprague de Camp" be sorted with the L's, or with the D's, or with the C's? Do you sort Japanese names according to their Kanji or according to Kana or according to Katakana? What letter would you sort the name Brian Peter George St John le Baptiste Eno de la Salle under? To answer that properly you have to know which cultural background the person is from, since different cultures sort the same variety of long name differently!
You have a couple of years of work ahead of you to do this assignment properly.
2 comentarios
Steven Lord
el 21 de En. de 2017
If you're trying to sort names, take a look at this webpage. [For some of the points on that page, consider this musician during a portion of 1993.]
Walter Roberson
el 22 de En. de 2017
Someone introduced me to that page last year, and I did a bit of poking around. The person who wrote that page was, if anything, an optimist :(
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!