1. 字符串的设定
在MATLAB 中的字符串一般是ASCII值的数值数组,它作为字符串表达式进行显示。MATLAB 对字符串的设定非常简单,只需用单引号(’)将需设定的字符串引注即可。
>> str='I have many good friends!'
str = I have many good friends!
>> whos
Name Size Bytes Class Attributes
str 1x25 50 char
2. 字符串的操作
字符串元素的读取
-利用数组操作工具进行读取
-使用disp函数显示字符串
>> str='I have many good friends!';
>> str
str = I have many good friends!
>> str(3)
ans = h
>> disp(str)
I have many good friends!
字符串的基本变换
字符串的ASCII码操作
使用char函数进行逆变换
字符串的执行
>> for n = 2:3
eval(['M' num2str(n) ' = magic(n)'])
end
M2 =
1 3
4 2
M3 =
8 1 6
3 5 7
4 9 2
常见字符串的操作
函