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 imread: The function imread can read an image file, for illustration a JPEG (.jpg) file. The function reads color images into a 3-dimensional matrix. >> myimage1

Finding a sting - function findstr: The function findstr receives two strings as input arguments. It finds all the occurrences of shorter string contained by the longer, and r

Comparing strings: There are few functions which compare strings and return logical true when they are equivalent or logical false when not. The function strcmp compares the s

Variable Scope: The scope of any of variable is the workspace in which it is valid. The workspace generated in the Command Window is known as the base workspace. As we know

Help command: The help command is used with the script rectarea, the function readlenwid, and the major function printrectarea. To see the first comment in the subfunction, as

Implementation of binary search: The binary search can be implemented as a recursive function. The recursive function below also implements this binary search algorithm. It re

Illustration of Image processing: This displays that there are 64 rows, or in another word, 64 colors, in this specific colormap. It also displays that the first five colors a

Built-in colormaps: The MATLAB has numerous built-in colormaps which are named; the reference page on colormap shows them. Calling the function colormap without passing any ar

Sound Files: The sound signal is an illustration of a continuous signal which is sampled to result in a discrete signal. In this situation, sound waves traveling through the a

Evaluating a string: The function eval is used to compute a string as a function. For illustration, below is the string 'plot(x)'is interpreted to be a call to plot the functi