>> str='I have many good friends!'
str =
I have many good friends!
>> whos
Name Size Bytes Class
EXPLODE 1x5 40 double array
F1 1x12 24 char array
F2 1x12 24 char array
X 1x5 40 double array
a 1x28 224 double array
ans 1x12 12 logical array
label 1x5 330 cell array
s1 1x10 20 char array
s2 1x10 20 char array
s3 1x11 22 char array
str 1x25 50 char array
w 1x19 38 char array
x 1x4 32 double array
Grand total is 173 elements using 876 bytes
>>
%另外,字符串内的单引号是由两个连续的单引号来表示。字符串连接可以直接从数组连接中得到。继续在命令窗口中输入如下语句,并按Enter键确认。
>>u='we must study hard!'
u =
we must study hard!
>> v='and we should never forget our country!'
v =
and we should never forget our country!
>> w=[u,v]
w =
we must study hard!and we should never forget our country!
>>
%如同矩阵,字符串可以有多个行,但每行必须有相同数目的列数。因此,要用空格以使所有行有相同长度,继续在命令窗口中输入如下语句,并按Enter键确认。
>> t=[' xiao ming kao shang le daxue'
'xiaofang meiyou kaoshangdaxue']
t =
xiao ming kao shang le daxue
xiaofang meiyou kaoshangdaxue
>>
%如果各列输入的字符串长度不一致时,MATLAB 7将给出错误的提示。继续在命令窗口中输入如下语句,并按Enter键确认。
>> t=[' xiao ming kao shang le daxue'
'xiaofang meiyou kaoshang daxue']
??? Error using ==> vertcat
All rows in the bracketed expression must have the same
number of columns.
>>
>> t=['China win 32 gold metals in the Olympic Games'
'and Chinese TAibei Team win 2 gold metals '
'That doesn''t mean any thing ']
t =
China win 32 gold metals in the Olympic Games
and Chinese TAibei Team win 2 gold metals
That doesn't mean any thing
>>
>> t=['China win 32 gold metals in the Olympic Games'
'and Chinese TAibei Team win 2 gold metals '
'That doesn''t mean any thing ']
??? Error using ==> vertcat
All rows in the bracketed expression must have the same
number of columns.