收藏 分销(赏)

MATLAB程序设计方案报告基于MATLAB动画播放及音乐播放.doc

上传人:快乐****生活 文档编号:2728346 上传时间:2024-06-05 格式:DOC 页数:15 大小:3.78MB
下载 相关 举报
MATLAB程序设计方案报告基于MATLAB动画播放及音乐播放.doc_第1页
第1页 / 共15页
MATLAB程序设计方案报告基于MATLAB动画播放及音乐播放.doc_第2页
第2页 / 共15页
MATLAB程序设计方案报告基于MATLAB动画播放及音乐播放.doc_第3页
第3页 / 共15页
MATLAB程序设计方案报告基于MATLAB动画播放及音乐播放.doc_第4页
第4页 / 共15页
MATLAB程序设计方案报告基于MATLAB动画播放及音乐播放.doc_第5页
第5页 / 共15页
点击查看更多>>
资源描述

1、MATLAB程序设计课程设计汇报设 计 题 目: 基于MATLAB动画演示 及背景音乐插入 专 业: 级通信工程 姓名(学号): 储兆雄 邓少林 徐凯越 指 导 教 师: 倪建军(博士/副教授)时 间: 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(*.m,choose moi

3、ve 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 reserved - to be defined in a future versio

4、n 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;imshow(A); axes axis(0 1 0 1);axis off;set(

5、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 1 if ishandle(h) return end for i=1:N temp=get(handles(i),position); step=get(handles(i),fontsize)/48*0.05; if temp

6、(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),position,temp,rotation,get(handles(i),ro

7、tation)+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参数,实现暂停和继续播放功效切换,而经过timerPause()函数来实现其功效程序实现代码以下:funct

8、ion 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 symPausetry if strcmp(get(handles.btnvpause,string),pause) handles.timer1 =

9、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 some error while excuting the func

10、tion!,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 future version of MATLAB% handle

11、s structure with handles and user data (see GUIDATA)try if 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(sorry, there are some error wh

12、ile 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 (see GUIDATA)global mfilepatht

13、ry 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 btnstart (see GCBO)% eventda

14、ta reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global mfilepath player signsign=false;try if mfilepath=0 data,Fs,nbits=wavread(mfilepath); else try data,Fs,nbits=wavread(you are a song in my heart.wav); catch msgbox(sorry,the defa

15、ult music does not exist,NOTICING); end end 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 handle to btnmpause (

16、see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global player signtry if strcmp(get(handles.btnmpause,string),pause) pause(player); set(handles.btnmpause,string,continue); elseif strcmp(get(handles.btnmpause,strin

17、g),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 be defined in a fut

18、ure 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_DeleteFcn(hObject, e

19、ventdata, 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 signtry if strcmp(sign,true) stop(player); close all endcatch msgbox(sorry, there are some error while

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

21、乐,此时动画会暂停,当音乐开始播放时,动画也恢复正常。从这个结果看,程序内部命令会相互影响,所以这将是我们队优化程序一个方向。5、改善方向从程序演示过程发觉以下问题,这将是本程序优化方向。(1)回调函数之间干扰:最显著结果表现为,动画运行过程中,点击其它按钮,将短时间暂停动画程序。所以怎样将动画独立于GUI之外,同时又受GUI界面按钮控制,这是程序优化关键之一。(2)动画程序编写模块:虽说本程序能够实现动画程序自由选择,但标准上还是选择了.m文件,而且在程序内部参数不知晓情况下编写,程序实现结果可能不一致。(3)动画模块完全是由程序文件实施,怎样能够动态将动画录制并保留,后者说直接播放.avi

22、格式动画,将是僵尸程序优化特色之一。(4)动画播放过程中,未能直接终止动画程序。(5)动画并行播放问题。能够让多个动画程序同时打开,但只有一个动画播放,其它被暂停,等其结束后,其它又能够继续实施。所以当要切换动画时,怎样自动停止已经播放动画,有待优化。6、心得体会经过此次maltab课设,加强了利用matlab编程能力。首先是GUI设计,其次则是代码编写。而程序实现不仅能够经过GUI写入代码,还能够直接经过代码绘制图形,控件,和callback函数等等。因为完成此次课设是从不懂到学会过程,期间查阅了很多书籍,同时在网上也借阅了她人经验结果,达成了编程质飞跃。然而在编程过程,曲折是显著,调试程序时,警告时不时地出现,从而了解了各类常常出现错误。其次,因为matlab更多是直接调用内部命令,所以说假如不清楚内部命令话,编程则显得很吃力,先动画音乐程序就是,大部分是调用命令。即使说本程序专题代码并不是很长,却要求了较高基础。了解命令后,则又显得很简单。不过像动画程序,大部分则是自己编写算法,更显自主性,这部分更能显示个人编程能力和严谨性。文件1 MATLAB GUI设计学习手记第二版 罗华飞 北京航天航空大学出版社2精通matlab+GUI设计第2版 陈垚光 电子工业出版社3MATLAB程序设计教程 李海涛 邓樱 高等教育出版社

展开阅读全文
相似文档                                   自信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 

客服