Illustration of sorting strings, MATLAB in Engineering

Illustration of Sorting strings:

To sort on the rows rather than second dimension should be specified.

>> sort(words,2)

ans =

Hello

Hdowy

Hi

Gbdeooy

Caio

It can be shown by this that the blank space comes before the letters of the alphabet in the character encoding, and that the uppercase letters also come before the lowercase letters.

Now the question is how the strings be sorted alphabetically? The MATLAB has a function sortrows which will do this. The way it works is that it checks the strings column-by-column beginning from the left. If it can establish which letter comes first, it picks up the whole string and puts it in the first row. In this illustration, the first two strings are placed depend on the first character, C and G. For other three strings, they all start with H so the later column is examined. In this situation the strings are placed depend on the second character, e, i, o.

>> sortrows(words)

ans =

Ciao

Goodbye

Hello

Hi

Howdy

Posted Date: 10/22/2012 7:47:28 AM | Location : United States







Related Discussions:- Illustration of sorting strings, Assignment Help, Ask Question on Illustration of sorting strings, Get Answer, Expert's Help, Illustration of sorting strings Discussions

Write discussion on Illustration of sorting strings
Your posts are moderated
Related Questions
Function iscellstr - string function: The function iscellstr will return the logical true when a cell array is a cell array of all the strings, or logical false if not. >>


Finding a sting - function strfind: The function strfind does necessarily similar thing, except that the order of the arguments does make dissimilarity. The common form is str

Illustration of Graphics properties: A particular property can also be exhibited, for illustration, to view the line width:     >> get(hl,'LineWidth')     ans =

Passing arguments to functions: In all these functions examples faraway, at least one of the arguments was passed in the function call to be the value(s) of the equivalent inp

Interchange rows : for illustration interchanging rows ri and rj is written as

Function strncmp: The function strncmp compares only the first n characters in the strings and ignores the rest. The initial two arguments are strings to compare, and third ar

Illustration of Variable scope: Running this function does not add any of variables to the workspace, as elaborated: >> clear >> who >> disp(mysum([5 9 1]))

Interpolation and extrapolation: In most cases, it is desired to estimate values other than at the sampled data points. For illustration, we may want to estimate what the temp

Illustration of Passing arguments to functions: Here is an illustration of calling this function: >> printrand() The random # is 0.94 As nothing is passed to