版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、MATLA程序设计课程设计报告设计题目: 基于MATLAB勺动画演示及背景音乐插入专 业:2011 级通信工程姓名(学号): 储兆雄13邓少林14徐凯越23指导教 师: 倪建军(博士/副教授)时 间:2013 年12月20日目录1、设计目的2、总体设计3、具体设计(功能实现)4、结果分析5、改进方向6、心得体文献附录1、设计目的学会运用matlab工具箱实现matlab GUI设计,处理动画运行,以及添加背景音 乐,并实现其动态操作,如继续、暂停等功能。2、总体设计主要包括:动画模块,音乐模块,动画显示模块3、具体设计(功能实现)1) 动画模块( 1)打开动画文件:从文件打开对话框选择动画程序
2、,实现动画播放的可选择性程序实现代码如下:function btnvopen_Callback(hObject, eventdata, handles)% hObject handle to btnvopen (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global vfname %动画文件名vfname vpname vindex=uigetfile( '*.
3、m' , 'choose moive file' ); len=length(vfname);if vindexset, 'string' ,vfname(1:len-2) end打开对话框效果如下:( 2)开始动画播放:先获取文件名称vfname(1:len-2) ,然后用run() 命令来执行程序实现代码如下:function btnvstart_Callback(hObject, eventdata, handles)% hObject handle to btnvstart (see GCBO)% eventdata reserved - to
4、be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global vfnametrylen=length(vfname);run(vfname(1:len-2);catchmsgbox( 'sorry, there are some error while playingmovie!' , 'NOTICING');end 以下是其中两个动画程序snowed画%* 设置背景*%A=imread( 'H:'
5、; );h=figure;imshow(A);axesaxis(0 1 0 1);axis off ;set(gcf, 'color' , 'k' );N=20;handles=zeros(1,N);x=rand(2,N);fontsize=floor(rand(1,N)*17+32);new_handles_N=0;%绘图for i=1:Nhandles(i)=text(x(1,i),x(2,i),'*' , 'fontsize' ,fontsize(i), 'color'w' )Jendwhile 1i
6、f ishandle(h)returnendfor i=1:N);)/48*;temp=get(handles(i),'position'step=get(handles(i),'fontsize'if temp(2)<0new_handles_N=new_handles_N+1;new_handles(new_handles_N)= copyobj(handles(i),gca);if new_handles_N=500delete(new_handles);new_handles_N=0;endtemp(1)=rand(1);temp(2)=1;els
7、etemp(2)=temp(2)-step;temp(1)=temp(1)+rand(1)* end)+set(handles(i), 'position' ,temp, 'rotation' ,get(handles(i), 'rotation' 5);endpause(.2)end简单程序动画tryMovie=moviein(16);for k=1:16plot(fft(eye(k+16)axisequalaxisoffM(k)=getframe;endmovie(M,30);catchmsgbox( 'sorry, there ar
8、e some error while playingmovie!' , 'NOTICING');end动画效果如下:( 3)暂停/ 继续功能:获取pause 按钮 string 参数,实现暂停和继续播放功能的切换,而通过 timerPause() 函数来实现其功能程序实现代码如下:function btnvpause_Callback(hObject, eventdata, handles)% hObject handle to btnvpause (see GCBO)% eventdata reserved - to be defined in a future ve
9、rsion of MATLAB% handles structure with handles and user data (see GUIDATA)global symPause tryif strcmp(get, 'string' ), 'pause' )= timer( 'Period' , , 'ExecutionMode' , 'singleShot' , 'timerFcn' timerPause);set, 'string' , 'continue' )
10、 start;elseif strcmp(get, 'string' ), 'continue' )symPause =0;set, 'string' , 'pause' ) endcatchmsgbox( 'sorry, there are some error while excuting the function!' , 'NOTICING', 'error' ); endfunction timerPause(hObject,eventdata,handles)global
11、symPausesymPause=1;while symPause=1pause(1)end( 4)添加文字function btnvshow_Callback(hObject, eventdata, handles)% hObject handle to btnvshow (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) tryif get, 'string
12、9; )set, 'string' ,get, 'string' ), .'visible' ,'on' ,'fontname' ,'? i ?' 'fontsize',;elseset, 'visible' , 'off' );msgbox( 'Add some words first!' );endcatchmsgbox( 'sorry, there are some error while excuting the fun
13、ction!' , 'NOTICING', 'error' );end 2)音乐模块( 1)打开音乐function btnmbrowse_Callback(hObject, eventdata, handles)% hObject handle to btnmbrowse (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global
14、 mfilepathtrymfname mpname mindex=uigetfile( '*.wav' , 'choose music' );if mindexmfilepath=mpname mfname;set, 'string' ,mfilepath); endcatchmsgbox( 'Error,while importing music £?; 'NOTICING', 'error'); end ( 2)播放音乐function btnstart_Callback(hObject,
15、eventdata, handles)% hObject handle to btnstart (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) global mfilepath player sign sign= 'false' ;tryif mfilepath=0data,Fs,nbits=wavread(mfilepath);elsetrydata,F
16、s,nbits=wavread('you are a song in my ');catchmsgbox( 'sorry,the default music does notexist' , 'NOTICING');endendplayer=audioplayer(data,Fs,nbits);play(player);sign= 'ture' ;set, 'string' , 'pause' , 'Enable' , 'on' );catchmsgbox( '
17、;Rrror while playing music!' , 'NOTICING');end( 3)暂停/ 继续功能function btnmpause_Callback(hObject, eventdata, handles)% hObject handle to btnmpause (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global p
18、layer signtryif strcmp(get, 'string' ), 'pause' )pause(player);set, 'string' , 'continue' );elseif strcmp(get, 'string' ), 'continue' )resume(player);set, 'string' , 'pause' );endcatchmsgbox( 'sorry, there are some error while excut
19、ing the function!', 'NOTICING' );end( 4)停止播放音乐function btnmstop_Callback(hObject, eventdata, handles)% hObject handle to btnmstop (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global player signtrys
20、top(player);sign= 'false' ;set, 'string' , 'pause' , 'Enable' , 'off' );catchmsgbox( 'ERROR', 'NOTICING' );end3)其他辅助功能( 1)关闭程序:在退出程序时,音乐不会自动停止,所以为了在退出程序时同时关闭音乐,才加入此功能function figure1_DeleteFcn(hObject, eventdata, handles)% hObject handle to fig
21、ure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global player sign tryif strcmp(sign, 'true' )stop(player);close allendcatchmsgbox( 'sorry, there are some error while excuting the function!'
22、, 'NOTICING', 'error' );end( 2)异常捕捉机制try-catch由于程序功能再设计上考虑的并不是十分全面,可能会出现预料不到的错误,因此加入此功能,避免在出现未知错误时,程序崩溃。4、结果分析功能实现上看,基本上能达到预期效果,各个功能均可正常执行,在动画播放方面,有些方面还不尽如人意,比如说,由于实现了动画的可切换性,也就是说动画程序的独立性,使得自己编写的m文件和程序内部参数部分不一致,使得出现不同效果,比如, 有时动画在设计好的GUI 界面上显示,有时又以独立的窗口运行。音乐模块则与预期一致。另外,应该说是非人为因素,在动画播放的时候,添加背景音乐,此时动画会暂停,当音乐开始播放时,动画也恢复正常。从这个结果看,程序内部命令会相互影响,所以这将是我们队优化程序的一个方向。5、改进方向从程序演示过程发现以下问题,这将是本程序优化的方向。(1) 回调函数之间的干扰:最明显的结果表现为,动画运行过程中,点击其他的按钮,将短时间暂停动画程序。所以如何将动画独立于GUI 之外, 同时又受GU
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 液氢原料供应保障可行性研究方案
- 双鸭山市辅警招聘面试题及答案
- 后端开发MyBatis框架题库及答案
- 踝关节扭伤护理查房
- 踝关节滑膜囊肿护理查房
- 建立自信超越自我
- 26年随访大数据平台建设指引
- 后天性尺骨畸形护理查房
- 引产赔偿协议合同
- 人工砍草合同范本
- GB/T 9799-2024金属及其他无机覆盖层钢铁上经过处理的锌电镀层
- DZ∕T 0348-2020 矿产地质勘查规范 菱镁矿、白云岩(正式版)
- 中医是怎样治疗动脉硬化的
- 产品漏装改善报告
- 悬挑式卸料平台监理实施细则
- 铸件(原材料)材质报告
- 提货申请单表
- 脑与认知科学概论PPT(第2版)完整全套教学课件
- 【初中化学】中国化学家-李寿恒
- 镭雕机作业指导书
- 生管指导手册(什么是PMC)
评论
0/150
提交评论