MATLAB程序設(shè)計報告--基于MATLAB動畫播放及音樂播放_第1頁
MATLAB程序設(shè)計報告--基于MATLAB動畫播放及音樂播放_第2頁
MATLAB程序設(shè)計報告--基于MATLAB動畫播放及音樂播放_第3頁
MATLAB程序設(shè)計報告--基于MATLAB動畫播放及音樂播放_第4頁
MATLAB程序設(shè)計報告--基于MATLAB動畫播放及音樂播放_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、2012-2013學(xué)年第二學(xué)期MATLAB課設(shè)MATLAB程序設(shè)計課程設(shè)計報告設(shè) 計 題 目: 基于MATLAB的動畫演示 及背景音樂插入 專 業(yè): 2011級通信工程 姓名(學(xué)號): 儲兆雄 1162310213 鄧少林 1162310214 徐凱越 1162310223 指 導(dǎo) 教 師: 倪建軍(博士/副教授)時 間: 2013年12月20日 目錄1、設(shè)計目的2、總體設(shè)計3、具體設(shè)計(功能實現(xiàn))4、結(jié)果分析5、改進方向6、心得體會文獻附錄1、設(shè)計目的學(xué)會運用matlab工具箱實現(xiàn)matlab GUI設(shè)計,處理動畫運行,以及添加背景音樂,并實現(xiàn)其動態(tài)操作,如繼續(xù)、暫停等功能。2、總體設(shè)計主要

2、包括:動畫模塊,音樂模塊,動畫顯示模塊3、具體設(shè)計(功能實現(xiàn))1) 動畫模塊(1)打開動畫文件:從文件打開對話框選擇動畫程序,實現(xiàn)動畫播放的可選擇性程序?qū)崿F(xiàn)代碼如下: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 GUIDA

3、TA)global vfname %動畫文件名vfname 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()命令來執(zhí)行程序?qū)崿F(xiàn)代碼如下:function btnvstart_Callback(hObject, eventdata, handles)% hObject handle to btnvsta

4、rt (see GCBO)% eventdata reserved - 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動畫%*設(shè)置背景*%A=im

5、read(H:YOU.jpg);h=figure;imshow(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 1 if ishandle(h) return end for i=1:N temp=get(

6、handles(i),position); step=get(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(

7、2)-step; end set(handles(i),position,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)暫停/繼續(xù)功能:獲

8、取pause按鈕string參數(shù),實現(xiàn)暫停和繼續(xù)播放功能的切換,而通過timerPause()函數(shù)來實現(xiàn)其功能程序?qū)崿F(xiàn)代碼如下: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 symPaus

9、etry if strcmp(get(handles.btnvpause,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

10、) endcatch msgbox(sorry, there are some 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)% eve

11、ntdata reserved - to be defined in a future version of MATLAB% handles 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(A

12、dd some words first!); endcatch msgbox(sorry, 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% handle

13、s structure with handles and user data (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

14、, 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 signsign=false;try if mfilepath=0 data,Fs,nbits=wavread(mfilepath); else try data,Fs,nbits

15、=wavread(you are a song in my heart.wav); catch msgbox(sorry,the default 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)暫停/繼續(xù)功能function btnmpause

16、_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 player signtry if strcmp(get(handles.btnmpause,string),pause) pause(player); set(handles.

17、btnmpause,string,continue); elseif strcmp(get(handles.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 handl

18、e 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 signtry stop(player); sign=false; set(handles.btnmpause,string,pause,Enable,off);catch msgbox(ERROR,NOTICING);end3)其他輔助功能(1)關(guān)閉程序:在退出程序時,

19、音樂不會自動停止,所以為了在退出程序時同時關(guān)閉音樂,才加入此功能function figure1_DeleteFcn(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 signtry if strcmp(sign,true) stop(

20、player); close all endcatch msgbox(sorry, there are some error while excuting the function!,NOTICING,error);end(2)異常捕捉機制try-catch由于程序功能再設(shè)計上考慮的并不是十分全面,可能會出現(xiàn)預(yù)料不到的錯誤,因此加入此功能,避免在出現(xiàn)未知錯誤時,程序崩潰。4、結(jié)果分析功能實現(xiàn)上看,基本上能達到預(yù)期效果,各個功能均可正常執(zhí)行,在動畫播放方面,有些方面還不盡如人意,比如說,由于實現(xiàn)了動畫的可切換性 ,也就是說動畫程序的獨立性,使得自己編寫的m文件和程序內(nèi)部參數(shù)部分不一致,使得出現(xiàn)不同效果,比如,有時動畫在設(shè)計好的GUI界面上顯示,有時又以獨立的窗口運行。音樂模塊則與預(yù)期一致。另外,應(yīng)該說是非人為因素,在動畫播放的時候,添加背景音樂,此時動畫會暫停,當音樂開始播放時,動畫也恢復(fù)正常。從這個結(jié)果看,程序內(nèi)部命令會相互影響,所以這將是我們隊優(yōu)化程序的一個方向。5、改進方向從程序演示過程發(fā)現(xiàn)以下問題,這將是本程序優(yōu)化的方向。(1)回調(diào)函數(shù)之間的干擾:最明顯的結(jié)果表現(xiàn)為,動畫運行過程中,點擊其他的按鈕,將短時間暫停動畫程序。所以如何將動畫獨立于GUI之外,同時又受GUI界面按鈕的控制,這是程序優(yōu)化重點之一。(2)動畫程序編寫模塊:雖說本程序可以實現(xiàn)動

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論