字符串的创建
要用单音号括起来,字符长度要一致,缺的话可以用空格补齐
country='China' 单引号
whos
name=['li yi' ;'hu xi'] 创建一个二维的数组 (字符串的长度要相等)
name=['li ying' ;'hu xi ']
使用deblank可以删除字符串里的空格(空格在第几行就写第几行)
trimname=deblank(name(2,:)) 第二行
字符串的比较
使用strcmp函数
字符串不相等返回0
比如
str1='hello';
str2='help';
strcmp(str1,str2)
ans
0 //字符串不相等
还可以在后面加参数比较字符串前n+1个字符。
比如添加2,表示前面3个字符
strcmp(str1,str2,2)
strcmp 会显示参数过多,用下面的函数
strncmp(str1,str2,2)
ans
1
关系运算图比较(属于对字符逐个比较)
A='face'
B=’cake‘
A==B
相同为 1 不同为 0
0 1 0 1