clc
myString = ' CS30 - Programming in Matlab'
myString =
CS30 - Programming in Matlab
isletter(myString)
ans =
Columns 1 through 13
0 1 1 0 0 0 0 0 1 1 1 1 1
Columns 14 through 26
1 1 1 1 1 1 0 1 1 0 1 1 1
Columns 27 through 29
1 1 1
isspace(myString)
ans =
Columns 1 through 13
1 0 0 0 0 1 0 1 0 0 0 0 0
Columns 14 through 26
0 0 0 0 0 0 1 0 0 1 0 0 0
Columns 27 through 29
0 0 0
isstrprop(myString,'alpha')
ans =
Columns 1 through 13
0 1 1 0 0 0 0 0 1 1 1 1 1
Columns 14 through 26
1 1 1 1 1 1 0 1 1 0 1 1 1
Columns 27 through 29
1 1 1
isstrprop(myString,'digit')
ans =
Columns 1 through 13
0 0 0 1 1 0 0 0 0 0 0 0 0
Columns 14 through 26
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 27 through 29
0 0 0
isstrprop(myString,'punct')
ans =
Columns 1 through 13
0 0 0 0 0 0 1 0 0 0 0 0 0
Columns 14 through 26
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 27 through 29
0 0 0
isstrprop(myString,'digit')
ans =
Columns 1 through 13
0 0 0 1 1 0 0 0 0 0 0 0 0
Columns 14 through 26
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 27 through 29
0 0 0
whos
Name Size Bytes Class Attributes
ans 1x29 29 logical
myString 1x29 58 char
myString(ans)
ans =
30
iskeyword(myString)
ans =
0
iskeyword('end')
ans =
1
iskeyword('if')
ans =
1
iskeyword('for')
ans =
1
iskeyword('start')
ans =
0
ischar(myString)
ans =
1
whos
Name Size Bytes Class Attributes
ans 1x1 1 logical
myString 1x29 58 char
ischar(ans)
ans =
0
myString = 'racecar'
myString =
racecar
myArray = [ 1 2 3 4 5]
myArray =
1 2 3 4 5
myArray(end:-1:1)
ans =
5 4 3 2 1
myString(end:-1:1)
ans =
racecar
strcmp(myString,myString(end:-1:1))
ans =
1
myString = 'a b c'
myString =
a b c
strcmp(myString,myString(end:-1:1))
ans =
0
myString(end:-1:1)
ans =
c b a
IsPalindrome('racecar')
ans =
1
IsPalindrome('Madam Im Adam')
ans =
0
sentence = 'Madam Im Adam'
sentence =
Madam Im Adam
isspace(sentence)
ans =
0 0 0 0 0 1 0 0 1 0 0 0 0
~isspace(sentence)
ans =
1 1 1 1 1 0 1 1 0 1 1 1 1
mask = ~isspace(sentence)
mask =
1 1 1 1 1 0 1 1 0 1 1 1 1
sentence(mask)
ans =
MadamImAdam
IsPalindrome(sentence(mask))
{Undefined function or variable 'sentence'.
Error in IsPalindrome (line 3)
nonSpaceMask = ~isspace(sentence);
}
IsPalindrome(sentence)
{Undefined function or variable 'sentence'.
Error in IsPalindrome (line 3)
nonSpaceMask = ~isspace(sentence);
}
sentence
sentence =
Madam Im Adam
IsPalindrome(sentence)
ans =
0
IsPalindrome(sentence)
reversedString =
madAmImadaM
ans =
0
IsPalindrome(sentence)
inString =
Madam Im Adam
reversedString =
madAmImadaM
ans =
0
IsPalindrome(sentence)
inString =
Madam Im Adam
inString =
MadamImAdam
reversedString =
madAmImadaM
ans =
0
IsPalindrome(sentence)
inString =
Madam Im Adam
inString =
MadamImAdam
reversedString =
madAmImadaM
ans =
1
IsPalindrome(sentence)
inString =
Madam Im Adam
inString =
MadamImAdam
reversedString =
madAmImadaM
ans =
1
upper(sentence)
ans =
MADAM IM ADAM
lower(sentence)
ans =
madam im adam
sentence
sentence =
Madam Im Adam
sentence
sentence =
Madam Im Adam
isletter(sentence)
ans =
1 1 1 1 1 0 1 1 0 1 1 1 1
clc
sentence
sentence =
Madam Im Adam
spaceMask = isspace(myString)
spaceMask =
0 1 0 1 0
find(spaceMask)
ans =
2 4
wordStartIndices = find(spaceMask) + 1
wordStartIndices =
3 5
spaceMask = isspace(sentence)
spaceMask =
0 0 0 0 0 1 0 0 1 0 0 0 0
find(spaceMask)
ans =
6 9
sentence
sentence =
Madam Im Adam
wordStartIndices = find(spaceMask) + 1
wordStartIndices =
7 10
sentence(7)
ans =
I
sentence(10)
ans =
A
wordStartIndices = [ 1, wordStartIndices ]
wordStartIndices =
1 7 10
myString = 'My favorite fruit is the orange.'
myString =
My favorite fruit is the orange.
strrep(myString,'orange','apple')
ans =
My favorite fruit is the apple.
myString = strrep(myString,'orange','apple')
myString =
My favorite fruit is the apple.
strfind(myString,'fruit')
ans =
13
myString = 'My favorite fruit is the apple and my second favorite fruit is the orange.'
myString =
My favorite fruit is the apple and my second favorite fruit is the orange.
strfind(myString,'fruit')
ans =
13 55
my2DArray = [ 1 2 3 4; 5 6 7 8]
my2DArray =
1 2 3 4
5 6 7 8
myStringArray = [ 'One'; 'Two' ]
myStringArray =
One
Two
myStringArray = [ 'One'; 'Two'; 'Three' ]
{Error using vertcat
Dimensions of matrices being concatenated are not consistent.
}
myStringArray = [ ['One',blanks(2)] ; ['Two',blanks(2)] ; 'Three' ]
myStringArray =
One
Two
Three
whos
Name Size Bytes Class Attributes
ans 1x2 16 double
mask 1x13 13 logical
my2DArray 2x4 64 double
myArray 1x5 40 double
myString 1x74 148 char
myStringArray 3x5 30 char
sentence 1x13 26 char
spaceMask 1x13 13 logical
wordStartIndices 1x3 24 double
myStringArray = char('One','Two','Three')
myStringArray =
One
Two
Three
myStringArray = char('One','Two','Three','Four)
myStringArray = char('One','Two','Three','Four)
|
{Error: A MATLAB string constant is not terminated properly.
}
myStringArray = char('One','Two','Three','Four')
myStringArray =
One
Two
Three
Four
myStringArray(1)
ans =
O
myStringArray(2)
ans =
T
myStringArray(2,3)
ans =
o
myStringArray(2,4)
ans =
myStringArray(2,5)
ans =
myStringArray(2,:)
ans =
Two
myStringArray(3,:)
ans =
Three
myStringArray(4,:)
ans =
Four
myStringArray(1,:)
ans =
One
myStringArray
myStringArray =
One
Two
Three
Four
myStringArray(:,2)
ans =
n
w
h
o
myStringArray(1,:)
ans =
One
myStringArray(3,:)
ans =
Three
num2str(123.456)
ans =
123.456
myString = num2str(123.456)
myString =
123.456
whos
Name Size Bytes Class Attributes
ans 1x7 14 char
mask 1x13 13 logical
my2DArray 2x4 64 double
myArray 1x5 40 double
myString 1x7 14 char
myStringArray 4x5 40 char
sentence 1x13 26 char
spaceMask 1x13 13 logical
wordStartIndices 1x3 24 double
myString = num2str([1 2 3 4 5])
myString =
1 2 3 4 5
frequencies = [ 2 7]
frequencies =
2 7
x = linspace(0,2*pi,100);
y1 = sin(frequencie(1)*x);
{Undefined function 'frequencie' for input arguments of type 'double'.
}
y1 = sin(frequencies(1)*x);
y2 = sin(frequencies(2)*x);
plot(x,y1,x,y2)
label1 = ['sin(',num2str(frequencies(1)),'*x)']
label1 =
sin(2*x)
label2 = ['sin(',num2str(frequencies(2)),'*x)']
label2 =
sin(7*x)
lengend(label1,label2)
{Undefined function 'lengend' for input arguments of type 'char'.
}
legend(label1,label2)
sprintf('%i',1239012)
ans =
1239012
sprintf('%5.2f',123.9012)
ans =
123.90
sscanf('123 456','%i')
ans =
123
456
diary off