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
Illustration of gauss-jordan elimination: An illustration of interchanging rows would be r1 ¬→ r3, that would results: Now, beginning with this matrix, an illustration of sc

Vector operations: As vectors are special cases of matrices, the matrix operations elaborated (addition, subtraction, multiplication, scalar multiplication, transpose) work on

Function used in sound files: The MATLAB has numerous other functions which let you read and play sound or audio files. In the audio files, sampled data for each audio channel

function numden: The function numden will return individually the numerator & denominator of a symbolic expression: >> sym(1/3 + 1/2) ans = 5/6 >> [n, d] =

Converting between the String and Number types: The MATLAB has many functions which convert numbers to strings in which each character element is a separate digit, and vice ve

Creating Cell arrays: There are many ways to create cell arrays. For illustration, we will create a cell array in which one element will store an integer, one element store ch

Algorithm for appex subfunction: The algorithm for appex subfunction is as shown:  Receives x & n as the input arguments.  Initializes a variable for running sum of t

IS Functions for Strings: There are many functions for strings, that return logical true or false. The function isletter returns the logical true when the character is a lette

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

Anonymous Functions: The anonymous function is a very easy, one-line function. The benefit of an anonymous function is that it does not have to be stored in an M-file. This ca