




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、MATLA程序設(shè)計(jì)課程設(shè)計(jì)報(bào)告設(shè)計(jì)題目:基于MATLAB勺動(dòng)畫(huà)演示專(zhuān)業(yè):姓名(學(xué)號(hào)):及背景音樂(lè)插入2011級(jí)通信工程儲(chǔ)兆雄13鄧少林14徐凱越23指導(dǎo)教師:倪建軍(博士/副教授)時(shí)間:2013年12月20日目錄1 設(shè)計(jì)目的2 總體設(shè)計(jì)3 具體設(shè)計(jì)(功能實(shí)現(xiàn))4結(jié)果分析5 改進(jìn)方向6 心得體會(huì)文獻(xiàn)附錄1、設(shè)計(jì)目的學(xué)會(huì)運(yùn)用matlab工具箱實(shí)現(xiàn)matlabGUI設(shè)計(jì),處理動(dòng)畫(huà)運(yùn)行,以及添加背景音樂(lè),并實(shí)現(xiàn)其動(dòng)態(tài)操作,如繼續(xù)、暫停等功能。2、總體設(shè)計(jì)主要包括:動(dòng)畫(huà)模塊,音樂(lè)模塊,動(dòng)畫(huà)顯示模塊3、具體設(shè)計(jì)(功能實(shí)現(xiàn))(1) 動(dòng)畫(huà)模塊(1) 打開(kāi)動(dòng)畫(huà)文件:從文件打開(kāi)對(duì)話(huà)框選擇動(dòng)畫(huà)程序,實(shí)現(xiàn)動(dòng)畫(huà)播放的可
2、選擇性程序?qū)崿F(xiàn)代碼如下:functionbtnvopen_Callback(hObject,eventdata,handles)%hObjecthandletobtnvopen(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)globalvfname%動(dòng)畫(huà)文件名vfnamevpnamevindex=uigetfile('*.m','choosemoivefile');len=length
3、(vfname);ifvindexset,'string',vfname(1:len-2)end打開(kāi)對(duì)話(huà)框效果如下:(2) 開(kāi)始動(dòng)畫(huà)播放:先獲取文件名稱(chēng)vfname(1:len-2),然后用run()命令來(lái)執(zhí)行程序?qū)崿F(xiàn)代碼如下:functionbtnvstart_Callback(hObject,eventdata,handles)%hObjecthandletobtnvstart(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserda
4、ta(seeGUIDATA)globalvfnametrylen=length(vfname);run(vfname(1:len-2);catchmsgbox('sorry,therearesomeerrorwhileplayingmovie!','NOTICING');end以下是其中兩個(gè)動(dòng)畫(huà)程序%*snow 動(dòng)畫(huà)設(shè)置背景*A=imread('H:');h=figure;imshow(A);axesaxis(0101);axisoff;set(gcf,'color','k');N=20;handles=zeros
5、(1,N);x=rand(2,N);fontsize=floor(rand(1,N)*17+32);new_handles_N=0;%繪圖fori=1:Nhandles(i)=text(x(1,i),x(2,i),'*','fontsize',fontsize(i),'color','w')endwhile1ifishandle(h)returnendfori=1:Ntemp=get(handles(i),'position');'fontsize')/48*;step=get(handles(i)
6、,iftemp(2)<0new_handles_N=new_handles_N+1;new_handles(new_handles_N)=copyobj(handles(i),gca);ifnew_handles_N=500delete(new_handles);new_handles_N=0;endtemp(1)=rand(1);temp(2)=1;elsetemp(1)=temp(1)+rand(1)*temp(2)=temp(2)-step;endset(handles(i),'position',temp,'rotation',get(handle
7、s(i),'rotation')+5);endpause(.2)end簡(jiǎn)單程序動(dòng)畫(huà)tryMovie=moviein(16);fork=1:16plot(fft(eye(k+16)axisequalaxisoffM(k)=getframe;endmovie(M,30);catchmsgbox('sorry,therearesomeerrorwhileplayingmovie!','NOTICING');end動(dòng)畫(huà)效果如下:(3) 暫停/繼續(xù)功能:獲取pause按鈕string參數(shù),實(shí)現(xiàn)暫停和繼續(xù)播放功能通過(guò)timerPause()函數(shù)來(lái)實(shí)現(xiàn)其功能程
8、序?qū)崿F(xiàn)代碼如下:functionbtnvpause_Callback(hObject,eventdata,handles)%hObjecthandletobtnvpause(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)globalsymPausetryifstrcmp(get,'string'),'pause')=timer('Period','Executi
9、onMode','singleShot','timerFcn'timerPause);set,'string','continue')start;elseifstrcmp(get,'string'),'continue')symPause=0;set,'string','pause')endcatchmsgbox('sorry,therearesomeerrorwhileexcutingthefunction!','NOTICING
10、39;,'error');endfunctiontimerPause(hObject,eventdata,handles)globalsymPausesymPause=1;whilesymPause=1pauseend(4) 添加文字functionbtnvshow_Callback(hObject,eventdata,handles)%hObjecthandletobtnvshow(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserd
11、ata(seeGUIDATA)tryifget,'string')set,'string',get,'string'),.'visible,'on','fontname','?i?;'fontsizeelseset,'visible,'off');msgbox('Addsomewordsfirst!');endcatchmsgbox('sorry,therearesomeerrorwhileexcutingthefunction!',&
12、#39;NOTICING','error');end2)音樂(lè)模塊(2) 打開(kāi)音樂(lè)functionbtnmbrowse_Callback(hObject,eventdata,handles)%hObjecthandletobtnmbrowse(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)globalmfilepathtrymfnamempnamemindex=uigetfile('*.
13、wav','choosemusic');ifmindexmfilepath=mpnamemfname;set,'string',mfilepath);endcatchmsgbox('Error,whileimportingmusic£?;'NOTICING','error');end(3) 播放音樂(lè)functionbtnstart_Callback(hObject,eventdata,handles)%hObjecthandletobtnstart(seeGCBO)%eventdatareserved-t
14、obedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)globalmfilepathplayersignsign='false'tryifmfilepath=0data,Fs,nbits=wavread(mfilepath);elsetrydata,Fs,nbits=wavread('youareasonginmy');catchmsgbox('sorry,thedefaultmusicdoesnotexist','NOTI
15、CING');endendplayer=audioplayer(data,Fs,nbits);play(player);sign='ture'set,'string','pause','Enable','on');catchmsgbox('Rrrorwhileplayingmusic!','NOTICING');end(4) 暫停/繼續(xù)功能functionbtnmpause_Callback(hObject,eventdata,handles)%hObjecthandleto
16、btnmpause(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)globalplayersigntryifstrcmp(get,'string'),'pause')pause(player);set,'string','continue');elseifstrcmp(get,'string'),'continue')re
17、sume(player);set,'string','pause');end,'NOTICING');catchmsgbox('sorry,therearesomeerrorwhileexcutingthefunction!'end(5) 停止播放音樂(lè)functionbtnmstop_Callback(hObject,eventdata,handles)%hObjecthandletobtnmstop(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%ha
18、ndlesstructurewithhandlesanduserdata(seeGUIDATA)globalplayersigntrystop(player);sign='false'set,'string','pause','Enable','off');catchmsgbox('ERROR','NOTICING');end3)其他輔助功能(1)關(guān)閉程序:在退出程序時(shí),音樂(lè)不會(huì)自動(dòng)停止,所以為了在退出程序時(shí)同時(shí)關(guān)閉音樂(lè),才加入此功能functionfigure1_DeleteFcn
19、(hObject,eventdata,handles)%hObjecthandletofigure1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)globalplayersigntryifstrcmp(sign,'true')stop(player);closeallendcatchmsgbox('sorry,therearesomeerrorwhileexcutingthefunction
20、!','NOTICING','error');end(2)異常捕捉機(jī)制try-catch由于程序功能再設(shè)計(jì)上考慮的并不是十分全面,可能會(huì)出現(xiàn)預(yù)料不到的錯(cuò)誤,因此加入此功能,避免在出現(xiàn)未知錯(cuò)誤時(shí),程序崩潰。4、結(jié)果分析功能實(shí)現(xiàn)上看,基本上能達(dá)到預(yù)期效果,各個(gè)功能均可正常執(zhí)行,在動(dòng)畫(huà)播放方面,有些方面還不盡如人意,比如說(shuō),由于實(shí)現(xiàn)了動(dòng)畫(huà)的可切換性,也就是說(shuō)動(dòng)畫(huà)程序的獨(dú)立性,使得自己編寫(xiě)的m文件和程序內(nèi)部參數(shù)部分不一致,使得出現(xiàn)不同效果,比如,有時(shí)動(dòng)畫(huà)在設(shè)計(jì)好的GUI界面上顯示,有時(shí)又以獨(dú)立的窗口運(yùn)行。音樂(lè)模塊則與預(yù)期一致。另外,應(yīng)該說(shuō)是非人為因素,在動(dòng)畫(huà)播放的時(shí)候,添加背景音樂(lè),此時(shí)動(dòng)畫(huà)會(huì)暫停,當(dāng)音樂(lè)開(kāi)始播放時(shí),動(dòng)畫(huà)也恢復(fù)正常。從這個(gè)結(jié)果看,程序內(nèi)部命令會(huì)相互影響,所以這將是我們隊(duì)優(yōu)化程序的一個(gè)方向。5、改進(jìn)方向從程序演示過(guò)程發(fā)現(xiàn)以下問(wèn)題,這將是本程序優(yōu)化的方向。(1) 回調(diào)函數(shù)之間的干擾:最明顯的結(jié)果表現(xiàn)為,動(dòng)畫(huà)運(yùn)行過(guò)程中,點(diǎn)擊其他的按鈕,將短時(shí)間暫停動(dòng)畫(huà)程序。所以如何將動(dòng)畫(huà)獨(dú)立于GUI之外,同時(shí)又受GUI界面按鈕的控制,這是程序優(yōu)化重點(diǎn)之一。(2) 動(dòng)畫(huà)程序編寫(xiě)模塊:雖說(shuō)本程序可以實(shí)現(xiàn)動(dòng)畫(huà)程
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 統(tǒng)編版六年級(jí)語(yǔ)文上冊(cè)課程教學(xué)計(jì)劃
- 個(gè)性化定制包裝設(shè)計(jì)-全面剖析
- 2025年玻璃清潔器項(xiàng)目投資風(fēng)險(xiǎn)評(píng)估報(bào)告
- 2025年重組水蛭素單克隆抗體項(xiàng)目投資風(fēng)險(xiǎn)評(píng)估報(bào)告
- 初中英語(yǔ)能力提升工作計(jì)劃
- 環(huán)境保護(hù)項(xiàng)目風(fēng)險(xiǎn)管理計(jì)劃概述
- 五年級(jí)數(shù)學(xué)上冊(cè)跨學(xué)科融合教學(xué)計(jì)劃
- 光伏發(fā)電項(xiàng)目施工組織計(jì)劃
- 近視眼防控科技研發(fā)計(jì)劃
- 部編版四年級(jí)上冊(cè)道法跨學(xué)科融合計(jì)劃
- 2025年陜西省西安交大附中中考數(shù)學(xué)一模試卷
- 依法執(zhí)業(yè)與醫(yī)療安全培訓(xùn)課件
- 2025年浙江郵電職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(kù)完整版
- 2025年湖南化工職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)傾向性測(cè)試題庫(kù)完美版
- DeepSeek介紹及其典型使用案例
- 物聯(lián)網(wǎng)+AI 助力水文現(xiàn)代化建設(shè)解決方案
- 《麥肯錫時(shí)間管理》課件
- 基于COMSOL動(dòng)網(wǎng)格的電磁軌道炮動(dòng)態(tài)電磁特性仿真
- 污水處理廠的改造與升級(jí)
- 2025年四川省國(guó)有資產(chǎn)經(jīng)營(yíng)投資管理有限責(zé)任公司招聘筆試參考題庫(kù)附帶答案詳解
- 安全駕駛培訓(xùn):路標(biāo)篇
評(píng)論
0/150
提交評(píng)論