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 =


>> length(' ')

ans =


>> length('')

ans =



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 =


>> mystr'

ans =



>> sent = 'Hello there';

>> length(sent)

ans =


>> 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
Three-Dimensional Plots: The MATLAB has many functions which will display three-dimensional plots. Most of these functions have similar name as corresponding two-dimensional p

Plot types: Besides plot and bar, there are another plot types like stem plots, histograms, stem plots, area plots and pie charts, and also other functions which customize the

Three-dimensional pie and bar: For the bar3 function, x & y vectors are passed and the function displays three-dimensional bars as shown in figure: Figure: Three-dimen

Recursive Functions: The Recursion occurs whenever something is defined in terms of itself. In the programming, a recursive function is a function which calls itself. The Recu

Writing variables to a File: The save command is used to write variables to a file, or to append the variables to a MAT-file. By the default, save function writes to a MAT-fil

Types of User-defined Functions: We know how to write a user-defined function, stored in an M-file, which computes and returns one value. This is merely one type of the functi

Creating string Variables: The string consists of a few numbers of characters (including, possibly, none). These are the illustrations of the strings: '' 'x' 'ca

Pie chart - plot functions: The MATLAB also has a function pie which will generate a pie chart. Calling the function with the form pie (vec) draws a pie chart, by using the pe

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 Empty vectors: The Empty vectors can also be used to delete elements from the arrays. For illustration, to remove the third element from array, an empty vector