Strings as vectors, MATLAB in Mathematics

Strings as Vectors:

The Strings are considered as vectors of characters-or in another words, a vector in which each and every element is a single character-so numerous vector operations can be performed. For illustration, the number of characters in a string can be found by using the length function:

 

>> length('cat')

ans =

3        

>> length(' ')

ans =

1

>> length('')

ans =

0

 

Notice that there is a distinction between an empty string, that has a length of zero, and a string consisting of a blank space, that has a length of one.

The Expressions can refer to a separate element, or a subset of a string or a transpose of the string:

>> mystr = 'Hi';

>> mystr(1)

ans =

H

>> mystr'

ans =

H

i

>> sent = 'Hello there';

>> length(sent)

ans =

11

>> sent(4:8)

ans =

lo th

 

Note that the blank space in the string is a valid character contained by the string.

Posted Date: 10/20/2012 4:29:39 AM | Location : United States







Related Discussions:- Strings as vectors, Assignment Help, Ask Question on Strings as vectors, Get Answer, Expert's Help, Strings as vectors Discussions

Write discussion on Strings as vectors
Your posts are moderated
Related Questions
sprintf function: The sprintf function works precisely like the fprintf function, but rather than printing it generates a string. Here are some illustrations in which the outp

Structure Consisting of the Fields A MATLAB can also solve the sets of equations. In this illustration, the solutions for x, y, & z are returned as a structure consisting of th

Built in recursive function in MATLAB: We have seen that the built-in function in MATLAB to compute factorials, termed as the factorial and we know how to implement the iterat

Illustration of Writing to files: Here is the other illustration in which a matrix is written to a file. At First, an arbitrary 2 × 4 matrix is generated, and then it is writt

Matrix of Plots: The other function which is very useful with any type of plot is subplot that creates a matrix of plots in the present Figure Window. The three arguments are

how can reconstruct just part of an image using imreconstruct?

Refer the subset of a matrix: It is also possible to refer to the subset of a matrix. For illustration, this refers to the first & second rows, second & third columns: >> m

Common form of the switch statement: The common form of the switch statement is as shown below:   switch switch_expression   case caseexp1    action1   case cas

Error-checking for integers: illustrations of running this script as shown below: >> readoneint Enter an integer: 9.5 Invalid! Enter an integer: 3.6 Invalid

Illustration of Labels and prompts: The program below prompts the user for endpoints (x1, y1) and (x2, y2) of a line segment, and computes the midpoint of the line segment, th