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
Calling of Function polyval: The curve does not appear very smooth on this plot, but that is as there are only five points in the x vector. To estimate the temperature

readlenwid function: function call: [length, width] = readlenwid; function header: function [l,w] = readlenwid In the function call, not any argument is passed; henc

Technique is to create one element - vector: Technique is to create one element with the values from one structure, and use repmat to replicate it to the preferred size. Then,

Example Exit modular program: In the illustration below, the user  Chose the Limit; -   Whenever prompted for n, entered the two invalid values before finally ente

Algorithm for the function e: The algorithm for the function eoption is as shown: Use the menu function to show the 4 choices. Error-check (an error would take place

Image Processing: The Images are represented as grids, or matrices, of picture elements (known as pixels). In MATLAB an image usually is represented as a matrix in which each

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

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

Tracing of Square matrices: The trace of a square matrix is the addition of all the elements on the diagonal. For illustration, for the preceding matrix it is 1 + 6 + 11 + 16,