文档详情

matlab字符,元胞,和结构数组.doc

发布:2017-04-04约4.15千字共8页下载文档
文本预览下载声明
字符数组 一个字符串由多个字符组成,用单引号(’)来界定。 na1=hello na1 = hello na2=this one is a3 na2 = this one is a3 na3=还支持中文呢 na3 = 还支持中文呢 whos 这个命令可查看字符数组的详细信息 Name Size Bytes Class Attributes na1 1x5 10 char na2 1x16 32 char na3 1x6 12 char class(na1) class可返回变量的类型 ans = char ischar(na1) 返回0或1,1代表字符型 ans = 1 strcat(na1,,,na2) 组合字符串 ans = hello,this one is a3 na4=double(na3) 将字符串str转换成数值数组 na4 = 36824 25903 25345 20013 25991 21602 na5=char(na4) 将数组转换为字符串 na5 = 还支持中文呢 na6=[na1;na2] 长度不相等所以出错 ??? Error using == vertcat CAT arguments dimensions are not consistent. na6=[na1,!,na2,na3] na6 = hello!this one is a3还支持中文呢 str2mat(na1,na2,na3) ans = hello this one is a3 还支持中文呢 strcat(na1,na2,na3) ans = hellothis one is a3还支持中文呢 char(na1,na2,na3) ans = hello this one is a3 还支持中文呢 na7=str2mat(na1,na2,na3) 将字符串足个写成行 na7 = hello this one is a3 还支持中文呢 na8=strvcat(na1,na2,na3) na8 = hello this one is a3 还支持中文呢 strcmp(na1,na2)比较na1 与na2是否相等 ans = 0 字符的分类, a=it is 12 a = it is 12 a1=isletter(a) 判断字符是否为字母 a1 = 1 1 0 1 1 0 0 0 a2=isspace(a) 判断字符是否为空格 a2 = 0 0 1 0 0 1 0 0 字符也可生成矩阵 b=[12;bb;pp] b = 12 bb pp 典型应用字符串函数,图形标注 画出正弦或余弦曲线 x=0:0.1:2; y=sin(x); %将x的最小值和最大值转化为字符串 s1=num2str(min(x)) s1 = 0 s2=num2str(max(x)) s2 = 2 将y的最小值和最大值转化为字符串 s3=num2str(min(y)) s3 = 0 s4=num2str(max(y)) s4 = 0.99957 ox=[变量的值从,s1,变化到,s2] ox = 变量的值从0变化到2 oy=[函数的值从,s3,变化到,s4] oy = 函数的值从0变化到0.99957 plot(x,y) 画出x和y标题 xlabel(ox) 标注x坐标的标题 ylabel(oy) 标注用 y坐标的标题 程序也可以简化: x=0:0.1:10; y=sin(x); ox=[x] oy=[y] plot(x,y) xlabel(ox) ylabel(oy) 元胞数组 元
显示全部
相似文档