本節主要是熟悉matlab字符數組的有關內置函數與技巧
字符數組有關操作:
A='Today is Saturday.';
B='I want go home.';
size(A)
size(B)
AB=strcat(A,B)
ab=strvcat(A,B)
size(ab)
double(ab)
>> XXBJ3_19
ans =
1 18
ans =
1 15
AB =
Today is Saturday.I want go home.
ab =
Today is Saturday.
I want go home.
ans =
2 18
ans =
84 111 100 97 121 32 105 115 32 83 97 116 117 114 100 97 121 46
73 32 119 97 110 116 32 103 111 32 104 111 109 101 46 32 32 32
字符串搜索
>> s='Find the starting indices of the shorter string.';
>> k=findstr(s,'the')
k =
6 30
>> k=findstr(s,'student')
k =
[]
>> k=findstr('the',s)
k =
6 30
字符串替換
>> S1='The area is at least 400 square meters';
>> newarea=strrep(S1,'400','1000')
newarea =
The area is at least 1000 square meters
ASCII碼應用
>> ASCII=char(reshape(32:127,32,3)')
ASCII =
!"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~