收藏 分销(赏)

MATLAB程序的设计报告__基于MATLAB动画播放与音乐播放.doc

上传人:二*** 文档编号:4516684 上传时间:2024-09-26 格式:DOC 页数:13 大小:3.78MB
下载 相关 举报
MATLAB程序的设计报告__基于MATLAB动画播放与音乐播放.doc_第1页
第1页 / 共13页
亲,该文档总共13页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

1、MATLAB程序设计课程设计报告设 计 题 目: 基于MATLAB的动画演示 及背景音乐插入 专 业: 2011级通信工程 (学号): 储兆雄 1162310213 邓少林 1162310214 徐凯越 1162310223 指 导 教 师: 倪建军(博士/副教授)时 间: 2013年12月20日目录1、设计目的2、总体设计3、具体设计(功能实现)4、结果分析5、改进方向6、心得体会文献附录1、设计目的学会运用matlab工具箱实现matlab GUI设计,处理动画运行,以及添加背景音乐,并实现其动态操作,如继续、暂停等功能。2、总体设计主要包括:动画模块,音乐模块,动画显示模块3、具体设计(

2、功能实现)1) 动画模块(1)打开动画文件:从文件打开对话框选择动画程序,实现动画播放的可选择性程序实现代码如下: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 %动画文件名vfn

3、ame vpname vindex=uigetfile(*.m,choose moive file);len=length(vfname);if vindex set(handles.txtvname,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 r

4、eserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global vfnametry len=length(vfname); run(vfname(1:len-2);catch msgbox(sorry, there are some error while playing movie!,NOTICING);end以下是其中两个动画程序snow动画%*设置背景*%A=imread(H:YOU.jpg);h=figure;i

5、mshow(A); axes axis(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:N handles(i)=text(x(1,i),x(2,i),*,fontsize,fontsize(i),color,w); endwhile 1if ishandle(h) returnendfor i=1:N temp=get(handles(i),position); step=ge

6、t(handles(i),fontsize)/48*0.05; if temp(2)0 new_handles_N=new_handles_N+1; new_handles(new_handles_N)= copyobj(handles(i),gca);if new_handles_N=500 delete(new_handles); new_handles_N=0;end temp(1)=rand(1); temp(2)=1;else temp(1)=temp(1)+rand(1)*0.1-0.05; temp(2)=temp(2)-step; end set(handles(i),posi

7、tion,temp,rotation,get(handles(i),rotation)+5); end pause(.2)end简单程序动画try Movie=moviein(16);for k=1:16 plot(fft(eye(k+16) axis equal axis off M(k)=getframe;end movie(M,30);catch msgbox(sorry, there are some error while playing movie!,NOTICING);end动画效果如下:(3)暂停/继续功能:获取pause按钮string参数,实现暂停和继续播放功能的切换,而通

8、过timerPause()函数来实现其功能程序实现代码如下:function btnvpause_Callback(hObject, eventdata, handles)% hObject handle to btnvpause (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global symPausetryif strcmp(get(handles.btnvpaus

9、e,string),pause) handles.timer1 = timer(Period, 0.1, ExecutionMode, singleShot,timerFcn, timerPause); set(handles.btnvpause,string,continue) start(handles.timer1); elseif strcmp(get(handles.btnvpause,string),continue) symPause =0; set(handles.btnvpause,string,pause)endcatch msgbox(sorry, there are s

10、ome error while excuting the function!,NOTICING,error);endfunction timerPause(hObject,eventdata,handles)global symPausesymPause=1;while symPause=1 pause(1)end(4)添加文字function btnvshow_Callback(hObject, eventdata, handles)% hObject handle to btnvshow (see GCBO)% eventdata reserved - to be defined in a

11、 future version of MATLAB% handles structure with handles and user data (see GUIDATA)tryif get(handles.txtvword,string) set(handles.stxtshow,string,get(handles.txtvword,string),.visible,on,fontname,fontsize,12.0);else set(handles.stxtshow,visible,off); msgbox(Add some words first!);endcatch msgbox(s

12、orry, there are some error while excuting the function!,NOTICING,error);end2)音乐模块(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 (

13、see GUIDATA)global mfilepathtry mfname mpname mindex=uigetfile(*.wav,choose music);if mindex mfilepath=mpname mfname; set(handles.edit1,string,mfilepath);endcatch msgbox(Error,while importing music,NOTICING,error);end(2)播放音乐function btnstart_Callback(hObject, eventdata, handles)% hObject handle to b

14、tnstart (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 signsign=false;tryif mfilepath=0 data,Fs,nbits=wavread(mfilepath);elsetry data,Fs,nbits=wavread(you are a song in my heart.wav);catc

15、h msgbox(sorry,the default music does not exist,NOTICING);endend player=audioplayer(data,Fs,nbits); play(player); sign=ture; set(handles.btnmpause,string,pause,Enable,on);catch msgbox(Rrror while playing music!,NOTICING);end(3)暂停/继续功能function btnmpause_Callback(hObject, eventdata, handles)% hObject

16、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 player signtryif strcmp(get(handles.btnmpause,string),pause) pause(player); set(handles.btnmpause,string,continue);elseif strcmp(get(hand

17、les.btnmpause,string),continue) resume(player); set(handles.btnmpause,string,pause);endcatch msgbox(sorry, there are some error while excuting the function!,NOTICING);end(4)停止播放音乐function btnmstop_Callback(hObject, eventdata, handles)% hObject handle to btnmstop (see GCBO)% eventdata reserved - to b

18、e defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global player signtry stop(player); sign=false; set(handles.btnmpause,string,pause,Enable,off);catch msgbox(ERROR,NOTICING);end3)其他辅助功能(1)关闭程序:在退出程序时,音乐不会自动停止,所以为了在退出程序时同时关闭音乐,才加入此功能function figure1_De

19、leteFcn(hObject, eventdata, handles)% hObject handle to figure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global player signtryif strcmp(sign,true) stop(player); close allendcatch msgbox(sorry, there are so

20、me error while excuting the function!,NOTICING,error);end(2)异常捕捉机制try-catch由于程序功能再设计上考虑的并不是十分全面,可能会出现预料不到的错误,因此加入此功能,避免在出现未知错误时,程序崩溃。4、结果分析功能实现上看,基本上能达到预期效果,各个功能均可正常执行,在动画播放方面,有些方面还不尽如人意,比如说,由于实现了动画的可切换性 ,也就是说动画程序的独立性,使得自己编写的m文件和程序部参数部分不一致,使得出现不同效果,比如,有时动画在设计好的GUI界面上显示,有时又以独立的窗口运行。音乐模块则与预期一致。另外,应该说是

21、非人为因素,在动画播放的时候,添加背景音乐,此时动画会暂停,当音乐开始播放时,动画也恢复正常。从这个结果看,程序部命令会相互影响,所以这将是我们队优化程序的一个方向。5、改进方向从程序演示过程发现以下问题,这将是本程序优化的方向。(1)回调函数之间的干扰:最明显的结果表现为,动画运行过程中,点击其他的按钮,将短时间暂停动画程序。所以如何将动画独立于GUI之外,同时又受GUI界面按钮的控制,这是程序优化重点之一。(2)动画程序编写模块:虽说本程序可以实现动画程序的自由选择,但原则上还是选择了.m文件,并且在程序部的参数不知晓的情况下编写,程序实现的结果可能不一致。(3)动画模块完全是由程序文件执

22、行的,如何能够动态的将动画录制并保存,后者说直接播放.avi格式的动画,将是僵尸程序优化的特色之一。(4)动画播放过程中,未能直接终止动画程序。(5)动画并行播放问题。可以让多个动画程序同时打开,但只有一个动画播放,其他的被暂停,等其结束后,其他的又可以继续执行。所以当要切换动画时,如何自动停止已经播放的动画,有待优化。6、心得体会通过此次的maltab课设,加强了运用matlab编程的能力。一方面是GUI设计,另一方面则是代码编写。而程序的实现不仅可以通过GUI写入代码,还可以直接通过代码绘制图形,控件,以及callback函数等等。因为完成此次课设是从不懂到学会的过程,期间查阅了很多书籍,

23、同时在网上也借阅了他人的经验成果,达到了编程质的飞跃。然而在编程的过程,曲折是明显的,调试程序时,警告时不时地出现,从而了解了各类经常出现的错误。其次,由于matlab更多的是直接调用部命令,所以说如果不清楚部命令的话,编程则显得很吃力,先动画音乐程序就是,大部分是调用命令。虽然说本程序主题代码并不是非常的长,却要求了较高的基础。了解命令后,则又显得很简单。但是像动画程序,大部分则是自己编写算法,更显自主性,这部分更能显示个人编程能力以及严谨性。文献1 MATLAB GUI设计学习手记第二版 罗华飞 航天航空大学2精通matlab+GUI设计第2版 垚光 电子工业3MATLAB程序设计教程 海涛 邓樱 高等教育12 / 13

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服