本文为matlab自学笔记的一部分,之所以学习matlab是因为其真的是人工智能无论是神经网络还是智能计算中日常使用的,非常重要的软件。也许最近其带来的一些负面消息对国内各个高校和业界影响很大。但是我们作为技术人员,更是要奋发努力,拼搏上进,学好技术,才能师夷长技以制夷,为中华之崛起而读书!
本文很多摘录自图书资料,不做任何商业用途,仅做技术分享,侵权删除!请不要放弃自己的理想和道路,加油!!
“参考书籍 《matlab 程序设计与综合应用》张德丰等著 感谢张老师的书籍,让我领略到matlab的便捷 《MATLAB技术大全》葛超等编著 感谢葛老师的书籍,让我领略到matlab的高效
(1)char(A):此函数将由正整数组成的矩阵转换成字符串矩阵,矩阵的元素一般要在0-65535之间,超出这个范围的是没有定义的,但也可以显示出结果,只是系统会给出超出范围的警告。(2)s=char(C):如果C是由字符串组成的单元阵,此函数将单元阵C转换成字符串矩阵,字符串矩阵的每行就是单元阵的每个元素,且用空格将每个字符串补齐,以保证字符串矩阵的合法性。也可以用cellstr()函数将一个字符串矩阵转换为一个字符串单元阵。
(3)s=char(sl,s2,s3,...)此函数以各个字符串是s1,s2,s3,...为每行构成字符串矩阵S,并自动以适当的空格追加在较短的字符串的后面,使各行的字符串的字符个数相同,以构造合法的字符串矩阵。参数中的空字符串也会被空格填充为相同大小的空格字符串。
char(65537)
s={'My' 'name' 'is' 'hello'}
k=char(s)
cellstr(k)
ans =
% 这个是越界了的输出的不知道是什么鬼东西
s =
'My' 'name' 'is' 'hello'
k =
My
name
is
hello
ans =
'My'
'name'
'is'
'hello'
format compact
for i=1:9
eval(['a' char(abs('0')+i) '=' char(abs('0')+i)])
end
a1 =
1
a2 =
2
a3 =
3
a4 =
4
a5 =
5
a6 =
6
a7 =
7
a8 =
8
a9 =
9
strcmp('hello','hello')
strcmp('hello','world')
c1={'my' 'name';'is' 'lilei'}% 元胞数组,单元数组
c2={'her' 'name';'is' 'lili'}
c3='NAME'
c4 = ['my' 'name';'is' 'olli'] % 普通char数组
c5 = ['my' 'name';'is' 'lili']
strcmp(c1,c2)
strcmp(c1,c3)
strcmp(c5,c4)
% ans =
% 1
% ans =
% 0
% c1 =
% 'my' 'name'
% 'is' 'lilei'
% c2 =
% 'her' 'name'
% 'is' 'lili'
% c3 =
% NAME
% c4 =
% myname
% isolli
% c5 =
% myname
% islili
% ans =
% 0 1
% 1 0
% ans =
% 0 0
% 0 0
% ans =
% 0
s1='Matlab';s2='MatLab';
strncmp(s1,s2,3)
strncmp(s1,s2,4)
c1={'good' 'bad';'Matlab' 'Matlab'}
c2='MatLab'
strncmp(c1,c2,3)
strncmp(c1,c2,4)
% ans =
% 1
% ans =
% 0
% c1 =
% 'good' 'bad'
% 'Matlab' 'Matlab'
% c2 =
% MatLab
% ans =
% 0 0
% 1 1
% ans =
% 0 0
% 0 0
k=strmatch('good',char('good','badgood','goodbad'))
s={'yes';'noyes';'yesno'}
strmatch('yes',s,'exact')
% k =
% 1
% 3
% s =
% 'yes'
% 'noyes'
% 'yesno'
% ans =
% 1
format compact
s='This is a good goose.'
b=findstr(s,'oo')
% s =
% This is a good goose.
% b =
% 12 17
format compact
strrep(s,'oo','ee')
str1={'matlab' 'welcome';'you' 'me'}
str2={'MatLab' 'lab';'good' 'software'}
str3={'mat' 'come';'you' 'me'}
strrep(str1,str3,str2)
strrep(str1,'me','you')
strrep('MatLab',str2,'!!!')
strrep('matlab','lab',str3)
% test_strrep
% ans =
% This is a geed geese.
% str1 =
% 'matlab' 'welcome'
% 'you' 'me'
% str2 =
% 'MatLab' 'lab'
% 'good' 'software'
% str3 =
% 'mat' 'come'
% 'you' 'me'
% ans =
% 'MatLablab' 'wellab'
% 'good' 'software'
% ans =
% 'matlab' 'welcoyou'
% 'you' 'you'
% ans =
% '!!!' 'MatLab'
% 'MatLab' 'MatLab'
% ans =
% 'matmat' 'matcome'
% 'matyou' 'matme'
(1)strtok('string',d):此函数返回由字符串d作为分割的字符串string的第1部分,也就是说,返回字符串strmg中第1个字符d之前的所有字符。如果字符串中不含有字符d则返回整个字符串;如果d字符恰为字符串string的第1个字符,则函数返回除第1个字符之外的所有字符。合法的d可以为任意字符或字符串,如果d为字符串,则将它的第1个字符作为分隔符。如果string中有前导空格,则前导空格将被忽略。(2)strtok('stnng'):此函数以默认的回车符(ASCII码为13)、制表符(ASCII码为9)、空格(ASCII码为32)作为分割符,前导空格将被忽略 (3)[token,rem]=strtok(•••):此函数不但返回上面的查找结果token,还返回剩余的字符串rem,其中不包括分割符,前导空格被忽略。其中strtok(...)可以为strtokok('string')或strtok('string',d)形式。
在这里插入图片描述