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.