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
Function fopen - file function: The permission string in the call to the fopen function identifies that the file is opened for writing to it. Just as when reading from a file,

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

Dimensions - matrix: The size and length functions in the MATLAB are used to find array dimensions. Length function returns the number of elements in the vector. The size func

Applications of Customized Strings: Labels, Prompts, Arguments to Functions: The one of very useful application of this is to involve numbers in strings that are used to plot

Built-in function for Differentiation: The MATLAB has a built-in function, diff that returns the differences between consecutive elements in a vector. For illustration, >>

Illustration of Spreadsheet Files: This reads the numbers in a double vector variable nums and the text in a cell array txt (the xlsread function forever returns the numbers f

Strcat function - Concatenation : The strcat function, though, will eliminate the trailing blanks from strings before concatenating. Note that in these illustrations, the trail

Customizing Plots : There are numerous ways to customize figures in the Figure Window. On clicking the Plot Tools icon will bring up the Property Editor & Plot Browser, with ma

Referring to and Modifying the Matrix Elements: To refer to matrix elements, the row and then the column indices are given in parentheses (always the row index initially and t

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