matlab字符串单元数组与结构体作业答案(共4页)_第1页
matlab字符串单元数组与结构体作业答案(共4页)_第2页
matlab字符串单元数组与结构体作业答案(共4页)_第3页
matlab字符串单元数组与结构体作业答案(共4页)_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上 1.编制一个脚本,查找给定字符串中指定字符出现的次数和位置;str='hopes,dreams,hold up,hold up'>> findstr(str,'o') %位置ans = 2 15 23>> a=findstr(str,'o');n=length(a) %次数n = 32编写一个脚本,判断输入字符串中每个单词的首字母是否为大写,若不是则将其修改为大写,其他字母为小写。>> str='i have a dream come true'nlength=len

2、gth(str);for k=1:nlength if (k=1 | isspace(str(k-1)&&(str(k)<='z'&&str(k)>='a')str(k)=char(double(str(k)-32); endenddisp(str);I Have A Dream Come True3创建2×2 单元数组,第1、2 个元素为字符串,第三个元素为整型变量,第四个元素为双精度(double)类型,并将其用图形表示。>> A=cell(2,2) A(1,1)='beijing&#

3、39; A(2,1)='BEIJING'A(1,2)=uint8(5);A(2,2)=1,2;4,7 cellplot(A)A = A = 'beijing' 5'BEIJING' 2x2 double4创建一个结构体,用于统计学生的情况,包括学生的姓名、学号、各科成绩等。然后使用该结构体对一个班级的学生成绩进行管理,如计算总分、平均分、排列名次等。>> student=struct('name','bam','mark','jimin','number'

4、,1,2,3,'scores',75,89,82,93,78,90,85,62,77 ,'subject','english,math,chinese','english,math,chinese','english,math,chinese')student = 1x3 struct array with fields: name number scores subject>> student(1)ans = name: 'bam' number: 1 scores: 75 89 82

5、 subject: 'english,math,chinese'>> student(2)ans = name: 'mark' number: 2 scores: 93 78 90 subject: 'english,math,chinese'>> student(3)ans = name: 'jimin' number: 3 scores: 85 62 77 subject: 'english,math,chinese'>> >> sum(student(1).sc

6、ores)ans = 246>> sum(student(2).scores)ans = 261>> sum(student(3).scores)ans = 224 mean(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 = 93 90 89 85 82 78 77 75 6

7、2index = 4 6 2 7 3 5 9 1 8>> student(1).mean= mean(student(1).scores)student(2).mean=mean(student(2).scores)student(3).mean= mean(student(3).scores)student = 1x3 struct array with fields: name number scores subject meanstudent = 1x3 struct array with fields: name number scores subject meanstud

8、ent = 1x3 struct array with fields: name number scores subject mean>> student(1)ans = name: 'bam' number: 1 scores: 75 89 82 subject: 'english,math,chinese' mean: 82>> student(2)ans = name: 'mark' number: 2 scores: 93 78 90 subject: 'english,math,chinese' mean: 87>> student(3)ans = name: 'jimin' number: 3 scores: 85 62 77 subject: 'english,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论