matlab字符串单元数组与结构体作业答案.docx

matlab字符串单元数组与结构体作业答案.docx

ID:53279490

大小:16.20 KB

页数:4页

时间:2020-04-02

matlab字符串单元数组与结构体作业答案.docx_第1页
matlab字符串单元数组与结构体作业答案.docx_第2页
matlab字符串单元数组与结构体作业答案.docx_第3页
matlab字符串单元数组与结构体作业答案.docx_第4页
资源描述:

《matlab字符串单元数组与结构体作业答案.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、1.编制一个脚本,查找给定字符串中指定字符出现的次数和位置;str=['hopes,dreams,holdup,holdup'];>>findstr(str,'o')%位置ans=21523>>a=findstr(str,'o');n=length(a)%次数n=32.编写一个脚本,判断输入字符串中每个单词的首字母是否为大写,若不是则将其修改为大写,其他字母为小写。>>str='ihaveadreamcometrue';nlength=length(str);fork=1:nlengthif(k==1

2、

3、isspace(str(k-1)))&&(str(k)<='z'&&str(k)>=

4、'a')str(k)=char(double(str(k))-32);endenddisp(str);IHaveADreamComeTrue3.创建2×2单元数组,第1、2个元素为字符串,第三个元素为整型变量,第四个元素为双精度(double)类型,并将其用图形表示。>>A=cell(2,2)A(1,1)={'beijing'};A(2,1)={'BEIJING'};A(1,2)={uint8(5)};A(2,2)={[1,2;4,7]}cellplot(A)A=[][][][]A='beijing'[5]'BEIJING'[2x2double]4.创建一个结构体,用于统计学生的情况,包

5、括学生的姓名、学号、各科成绩等。然后使用该结构体对一个班级的学生成绩进行管理,如计算总分、平均分、排列名次等。>>student=struct('name',{'bam','mark','jimin'},'number',{1,2,3},'scores',{[75,89,82],[93,78,90],[85,62,77]},'subject',{'english,math,chinese','english,math,chinese','english,math,chinese'})student=1x3structarraywithfields:namenumberscoressubj

6、ect>>student(1)ans=name:'bam'number:1scores:[758982]subject:'english,math,chinese'>>student(2)ans=name:'mark'number:2scores:[937890]subject:'english,math,chinese'>>student(3)ans=name:'jimin'number:3scores:[856277]subject:'english,math,chinese'>>>>sum(student(1).scores)ans=246>>sum(student(2).scor

7、es)ans=261>>sum(student(3).scores)ans=224mean(student(1).scores)ans=82>>mean(student(2).scores)ans=87>>mean(student(3).scores)ans=74.6667>>[new,index]=sort([student.scores],'descend')new=939089858278777562index=462735918>>student(1).mean=mean(student(1).scores)student(2).mean=mean(student(2).scor

8、es)student(3).mean=mean(student(3).scores)student=1x3structarraywithfields:namenumberscoressubjectmeanstudent=1x3structarraywithfields:namenumberscoressubjectmeanstudent=1x3structarraywithfields:namenumberscoressubjectmean>>student(1)ans=name:'bam'number:1scores:[758982]subject:'english,math,chin

9、ese'mean:82>>student(2)ans=name:'mark'number:2scores:[937890]subject:'english,math,chinese'mean:87>>student(3)ans=name:'jimin'number:3scores:[856277]subject:'english,math,chinese'mean:74.6667>>[new,index]=sort([student

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。