《MATLAB與仿真系統(tǒng)課程設(shè)計》_第1頁
《MATLAB與仿真系統(tǒng)課程設(shè)計》_第2頁
《MATLAB與仿真系統(tǒng)課程設(shè)計》_第3頁
《MATLAB與仿真系統(tǒng)課程設(shè)計》_第4頁
《MATLAB與仿真系統(tǒng)課程設(shè)計》_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

PAGEPAGE2自動化專業(yè)課程設(shè)計報告《MATLAB與仿真系統(tǒng)課程設(shè)計》班級姓名學(xué)號時間2010.12.13-2010.12.17地點電信實驗中心軟件機房指導(dǎo)教師鄧長輝大連海洋大學(xué)信息工程學(xué)院自動化教研PAGE19-大連海洋大學(xué)課程設(shè)計報告紙學(xué)院(系):專業(yè)班級:姓名:學(xué)號:圖像與動畫一、課程設(shè)計的目的與要求1、課程設(shè)計目的:(1)進一步理解和消化書本知識,運用所學(xué)知識和技能進行簡單的設(shè)計。(2)通過課程設(shè)計提高應(yīng)用能力,為專業(yè)課的學(xué)習(xí)打下基礎(chǔ)。(3)培養(yǎng)查閱資料的習(xí)慣,訓(xùn)練和提高獨立思考和解決問題的能力。(4)通過命令的調(diào)用來顯示磁盤目錄下的某個圖像;完成簡單動畫的制作,結(jié)合GUI可視化程序設(shè)計培養(yǎng)知識綜合運用能力和技巧。2、課程設(shè)計要求從課程設(shè)計的目的出發(fā),通過設(shè)計工作的各個環(huán)節(jié),達到以下要求:(1)能夠正確理解課程設(shè)計的題目和意義,全面思考問題。(2)運用科學(xué)合理的方法,認真按時完成。二、課程設(shè)計課題的分析MATLAB提供了一種能力,它可以存儲一系列各種類型的二維或三維圖,然后像放電影一樣把它們按次序重放出來。在某種意義上,動畫提供的運動為圖形增加另一個維數(shù)。通常圖形的次序不必以任意的方式關(guān)聯(lián)起來。一種明顯的動畫類型是取出三維圖形然后緩慢地將它旋轉(zhuǎn),這樣我們就可以從不同角度來觀察它。另一種類型是當一個參數(shù)變化時,依次顯示某些問題解的圖形。MATLAB中的函數(shù)moviein,getframe和movie提供了捕捉和播放動畫的所需工具。函數(shù)moviein可以產(chǎn)生一個幀矩陣來存放動畫中的幀;函數(shù)getframe對當前的圖像進行快照;而函數(shù)movie按順序回放各幀。照這樣,捕捉和回放動畫的方法是:(1)創(chuàng)建幀矩陣;(2)對動畫中的每一幀生成圖形,并把它捕捉到到幀矩陣里;(3)從幀矩陣里回放動畫。1、結(jié)合本身所學(xué)知識以及課程設(shè)計要求,確立自我方案的整體設(shè)計整體設(shè)計一個可視化模塊,該模塊分圖像顯示模塊和動畫播放模塊。圖像顯示模塊主要是用來顯示磁盤目錄下的某個圖片;動畫播放模塊主要是用來播放動畫。2、對整體方案進行劃分,分模塊對各個小問題進行解決圖片顯示模塊:在MATLAB中鍵入所需代碼,使其能夠調(diào)用磁盤目錄下的圖片文檔;動畫播放模塊:在MATLAB中鍵入所需代碼,使其能夠播放動畫;GUI的設(shè)計:建立一個GUI的模板,使其能都搭載圖片顯示模塊和動畫播放模塊。3、對各個模塊進行整合,使其工作三、課程設(shè)計的內(nèi)容與安排通過編程顯示磁盤目錄下的圖像文件,對GUI中的CALLBACK進行編程,使其能夠完成調(diào)用圖片這一功能;編程實現(xiàn)不斷變化的圖形,該圖為自己繪制,且觀賞價值高。時間安排參考如下教學(xué)時間安排教學(xué)安排周一布置任務(wù),查閱資料周二設(shè)計周三設(shè)計周四仿真、調(diào)試周五驗收、總結(jié)報告四、課程設(shè)計的步驟1、圖片顯示模塊的設(shè)計。圖片顯示模塊是為了在MATLAB中顯示本地磁盤中的圖片文檔而建立的一個模塊打開MATLAB程序,在彈出的“commandwindow”窗口中鍵入以下代碼:%=======================照片讀取=================================[x,cmap]=imread('E:\picture\走走走\100815\DSC00285.JPG');image(x);colormap(cmap);axisimageoff該段代碼調(diào)用的是本地磁盤E:\picture\走走走\100815\目錄的下DSC00285.JPG圖片文檔2、動畫播放模塊的設(shè)計動畫播放模塊是為了在MATLAB環(huán)境下繪制和播放動畫而建立的一個模塊打開MATLAB編輯器,在空白處鍵入以下代碼:(1).布朗運動的代碼%=====================布朗運動==================================n=50;%指定布朗運動的點數(shù)s=0.02;%指定溫度或速率%產(chǎn)生n個隨機點(x,y),處于-0.5到0.5之間%==================================x=rand(n,1)-0.5;y=rand(n,1)-0.5;h=plot(x,y,'.');%繪制隨機點axis([-11-11]);axissquareshadinginterpgridoffset(h,'EraseMode','Xor','MarkerSize',20);%設(shè)置擦除模式為Xor%循環(huán)5000次,產(chǎn)生動畫效果%==================================fori=linspace(1,10,5000)drawnowx=x+s*randn(n,1);%在坐標點附近添加隨機噪聲y=y+s*randn(n,1);set(h,'XData',x,'YData',y);%通過改變數(shù)據(jù)屬性來重新繪圖end(2).球體運動動畫的代碼%==============================小球運動========================fill([6,7,7,6],[5,5,0,0],[0,0.5,0]);%右邊豎條的填充holdon;%保持當前圖形及軸系的所有特性fill([2,6,6,2],[3,3,0,0],[0,0.5,0]);%左邊豎條的填充holdon;%保持當前圖形及軸系的所有特性t1=0:pi/60:pi;plot(4-2*sin(t1-pi/2),5-2*cos(t1-pi/2));%繪制中間的凹弧圖形grid;%添加網(wǎng)格線axis([0,9,0,9]);%定義坐標軸的比例axis('off');%關(guān)閉所有軸標注,標記,背景fill([1,2,2,1],[5,5,0,0],[0,0.5,0]);%中間長方形的填充holdon;%保持當前圖形及軸系的所有特性title('Sphere');%定義圖題x0=6;y0=5;head1=line(x0,y0,'color','b','linestyle','.',...'erasemode','xor','markersize',30);head2=line(x0,y0,'color','b','linestyle','.',...'erasemode','xor','markersize',50);%設(shè)置小球顏色,大小,線條的擦拭方式t=0;%設(shè)置小球的初始值dt=0.001;%設(shè)置運動周期t1=0;%設(shè)置大球的初始值dt1=0.001;while1%條件表達式t=t+dt;x1=9-1*t;y1=5;x3=6;y3=5;ift>0x2=6;y2=5;%設(shè)置小球的運動軌跡endift>2.8t=t+dt;a=sin(t-3);x1=6.1;y1=5.1;x3=4-2*sin(1.5*a);y3=5-2*cos(1.5*a);%設(shè)置大球的運動軌跡endset(head1,'xdata',x1,'ydata',y1);%設(shè)置球的運動set(head2,'xdata',x3,'ydata',y3);drawnow;endguide3、GUI的設(shè)計建立一個GUI的模板,使其能都搭載圖片顯示模塊和動畫播放模塊(1)打開MATLAB軟件,在彈出的“commandwindow”中鍵入:guide回車,彈出如圖1:圖1.GUI設(shè)計啟動窗口(2)選擇“BlankGUI(Default)”點擊“OK”按鈕進入GUI編輯窗口,如圖2:圖2.GUI編輯窗口(3)添加組件。組件名稱數(shù)量StringTagFrontSizeaxespushbutton14——BrownianSpherePictureQuitaxes1BT_BrownianBT_SphereBT_PictureShowBT_Quit10.010.010.010.010.0表1.組件列表及部分屬性設(shè)置圖3.組件的擺放在GUI界面內(nèi)添加組件如圖3所示,在修改完部分屬性以后界面如圖5所示,修改界面如圖4所示。圖4.屬性編輯欄圖5.屬性修改完后的GUI界面(4)菜單欄的設(shè)置(這里不添加默認的菜單欄,即GUI界面的MenuBar屬性設(shè)置為none)圖6.菜單欄的編輯為菜單欄添加組件組件清單如表2所示,組件添加如圖7所示圖7.菜單欄的修改名稱數(shù)量LabelTagAcceleratorNewMenNewMenuItemu46FileBackColorHelpAbouBrownianSpherePictureShowExitYellowRedNM_FileNM_BackColorNM_HelpNM_AboutNMI_BrownianNMI_SphereNMI_PictureShowNMI_ExitNMI_YellowNMI_RedCtrl+BCtrl+SCtrl+PCtrl+E表2.菜單欄的部分屬性設(shè)置(5)其余設(shè)置GUI界面的Tag屬性設(shè)為“CourseExercise”中文意思為“課程設(shè)計”4、代碼的添加以及模塊的組合封裝按鈕Quit功能實現(xiàn):%ExecutesonbuttonpressinBT_Quit.functionBT_Quit_Callback(hObject,eventdata,handles)%hObjecthandletoBT_Quit(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%<BT_Quit>=================================================================close(gcf)%</BT_Quit>================================================================注:個人習(xí)慣在自己添加的代碼處添加注釋頭文件%<>========尾文件%</>========按鈕Brownian功能實現(xiàn):%ExecutesonbuttonpressinBT_Brownian.functionBT_Brownian_Callback(hObject,eventdata,handles)%hObjecthandletoBT_Brownian(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%<BT_Brownian>=============================================================%=====================布朗運動==================================n=50;%指定布朗運動的點數(shù)s=0.02;%指定溫度或速率%產(chǎn)生n個隨機點(x,y),處于-0.5到0.5之間%==================================x=rand(n,1)-0.5;y=rand(n,1)-0.5;h=plot(x,y,'.');%繪制隨機點axis([-11-11]);axissquareshadinginterpgridoffset(h,'EraseMode','Xor','MarkerSize',20);%設(shè)置擦除模式為Xor%循環(huán)5000次,產(chǎn)生動畫效果%==================================fori=linspace(1,10,5000)drawnowx=x+s*randn(n,1);%在坐標點附近添加隨機噪聲y=y+s*randn(n,1);set(h,'XData',x,'YData',y);%通過改變數(shù)據(jù)屬性來重新繪圖end%</BT_Brownian>============================================================按鍵Sphere功能實現(xiàn):%ExecutesonbuttonpressinBT_Sphere.functionBT_Sphere_Callback(hObject,eventdata,handles)%hObjecthandletoBT_Sphere(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%<BT_Sphere>===============================================================%==============================小球運動========================fill([6,7,7,6],[5,5,0,0],[0,0.5,0]);%右邊豎條的填充holdon;%保持當前圖形及軸系的所有特性fill([2,6,6,2],[3,3,0,0],[0,0.5,0]);%左邊豎條的填充holdon;%保持當前圖形及軸系的所有特性t1=0:pi/60:pi;plot(4-2*sin(t1-pi/2),5-2*cos(t1-pi/2));%繪制中間的凹弧圖形grid;%添加網(wǎng)格線axis([0,9,0,9]);%定義坐標軸的比例axis('off');%關(guān)閉所有軸標注,標記,背景fill([1,2,2,1],[5,5,0,0],[0,0.5,0]);%中間長方形的填充holdon;%保持當前圖形及軸系的所有特性title('Sphere');%定義圖題x0=6;y0=5;head1=line(x0,y0,'color','b','linestyle','.',...'erasemode','xor','markersize',30);head2=line(x0,y0,'color','b','linestyle','.',...'erasemode','xor','markersize',50);%設(shè)置小球顏色,大小,線條的擦拭方式t=0;%設(shè)置小球的初始值dt=0.001;%設(shè)置運動周期t1=0;%設(shè)置大球的初始值dt1=0.001;while1%條件表達式t=t+dt;x1=9-1*t;y1=5;x3=6;y3=5;ift>0x2=6;y2=5;%設(shè)置小球的運動軌跡endift>2.8t=t+dt;a=sin(t-3);x1=6.1;y1=5.1;x3=4-2*sin(1.5*a);y3=5-2*cos(1.5*a);%設(shè)置大球的運動軌跡endset(head1,'xdata',x1,'ydata',y1);%設(shè)置球的運動set(head2,'xdata',x3,'ydata',y3);drawnow;end%</BT_Sphere>==============================================================按鈕PictureShow功能實現(xiàn):%ExecutesonbuttonpressinBT_PictureShow.functionBT_PictureShow_Callback(hObject,eventdata,handles)%hObjecthandletoBT_PictureShow(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%<BT_PictureShow>==========================================================%=======================照片讀取=================================[x,cmap]=imread('E:\picture\走走走\100815\DSC00285.JPG');image(x);colormap(cmap);axisimageoff%</BT_PictureShow>=========================================================顏色的實現(xiàn):%functionNMI_Red_Callback(hObject,eventdata,handles)%hObjecthandletoNMI_Red(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%=========================================set(handles.CourseExercise,'color','r');%背景色為紅色%=========================================%functionUntitled_3_Callback(hObject,eventdata,handles)%hObjecthandletoUntitled_3(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%functionNMI_Yellow_Callback(hObject,eventdata,handles)%hObjecthandletoNMI_Yellow(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%=========================================set(handles.CourseExercise,'color','y');%背景色為黃色%=========================================五、課程設(shè)計的結(jié)果程序所有代碼為:functionvarargout=CourseExercise(varargin)%COURSEEXERCISEM-fileforCourseExercise.fig%COURSEEXERCISE,byitself,createsanewCOURSEEXERCISEorraisestheexisting%singleton*.%%H=COURSEEXERCISEreturnsthehandletoanewCOURSEEXERCISEorthehandleto%theexistingsingleton*.%%COURSEEXERCISE('CALLBACK',hObject,eventData,handles,...)callsthelocal%functionnamedCALLBACKinCOURSEEXERCISE.Mwiththegiveninputarguments.%%COURSEEXERCISE('Property','Value',...)createsanewCOURSEEXERCISEorraisesthe%existingsingleton*.Startingfromtheleft,propertyvaluepairsare%appliedtotheGUIbeforeCourseExercise_OpeningFunctiongetscalled.An%unrecognizedpropertynameorinvalidvaluemakespropertyapplication%stop.AllinputsarepassedtoCourseExercise_OpeningFcnviavarargin.%%*SeeGUIOptionsonGUIDE'sToolsmenu.Choose"GUIallowsonlyone%instancetorun(singleton)".%%Seealso:GUIDE,GUIDATA,GUIHANDLES%Copyright2002-2003TheMathWorks,Inc.%EdittheabovetexttomodifytheresponsetohelpCourseExercise%LastModifiedbyGUIDEv2.516-Dec-201022:35:39%Begininitializationcode-DONOTEDITgui_Singleton=1;gui_State=struct('gui_Name',mfilename,...'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@CourseExercise_OpeningFcn,...'gui_OutputFcn',@CourseExercise_OutputFcn,...'gui_LayoutFcn',[],...'gui_Callback',[]);ifnargin&&ischar(varargin{1})gui_State.gui_Callback=str2func(varargin{1});endifnargout[varargout{1:nargout}]=gui_mainfcn(gui_State,varargin{:});elsegui_mainfcn(gui_State,varargin{:});end%Endinitializationcode-DONOTEDIT%ExecutesjustbeforeCourseExerciseismadevisible.functionCourseExercise_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%varargincommandlineargumentstoCourseExercise(seeVARARGIN)%ChoosedefaultcommandlineoutputforCourseExercisehandles.output=hObject;%Updatehandlesstructureguidata(hObject,handles);%UIWAITmakesCourseExercisewaitforuserresponse(seeUIRESUME)%uiwait(handles.figure1);%Outputsfromthisfunctionarereturnedtothecommandline.functionvarargout=CourseExercise_OutputFcn(hObject,eventdata,handles)%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Getdefaultcommandlineoutputfromhandlesstructurevarargout{1}=handles.output;%ExecutesonbuttonpressinBT_Brownian.functionBT_Brownian_Callback(hObject,eventdata,handles)%hObjecthandletoBT_Brownian(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%<BT_Brownian>=============================================================%=====================布朗運動==================================n=50;%指定布朗運動的點數(shù)s=0.02;%指定溫度或速率%產(chǎn)生n個隨機點(x,y),處于-0.5到0.5之間%==================================x=rand(n,1)-0.5;y=rand(n,1)-0.5;h=plot(x,y,'.');%繪制隨機點axis([-11-11]);axissquareshadinginterpgridoffset(h,'EraseMode','Xor','MarkerSize',20);%設(shè)置擦除模式為Xor%循環(huán)5000次,產(chǎn)生動畫效果%==================================fori=linspace(1,10,5000)drawnowx=x+s*randn(n,1);%在坐標點附近添加隨機噪聲y=y+s*randn(n,1);set(h,'XData',x,'YData',y);%通過改變數(shù)據(jù)屬性來重新繪圖end%</BT_Brownian>============================================================%ExecutesonbuttonpressinBT_Sphere.functionBT_Sphere_Callback(hObject,eventdata,handles)%hObjecthandletoBT_Sphere(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%<BT_Sphere>===============================================================%==============================小球運動========================fill([6,7,7,6],[5,5,0,0],[0,0.5,0]);%右邊豎條的填充holdon;%保持當前圖形及軸系的所有特性fill([2,6,6,2],[3,3,0,0],[0,0.5,0]);%左邊豎條的填充holdon;%保持當前圖形及軸系的所有特性t1=0:pi/60:pi;plot(4-2*sin(t1-pi/2),5-2*cos(t1-pi/2));%繪制中間的凹弧圖形grid;%添加網(wǎng)格線axis([0,9,0,9]);%定義坐標軸的比例axis('off');%關(guān)閉所有軸標注,標記,背景fill([1,2,2,1],[5,5,0,0],[0,0.5,0]);%中間長方形的填充holdon;%保持當前圖形及軸系的所有特性title('Sphere');%定義圖題x0=6;y0=5;head1=line(x0,y0,'color','b','linestyle','.',...'erasemode','xor','markersize',30);head2=line(x0,y0,'color','b','linestyle','.',...'erasemode','xor','markersize',50);%設(shè)置小球顏色,大小,線條的擦拭方式t=0;%設(shè)置小球的初始值dt=0.001;%設(shè)置運動周期t1=0;%設(shè)置大球的初始值dt1=0.001;while1%條件表達式t=t+dt;x1=9-1*t;y1=5;x3=6;y3=5;ift>0x2=6;y2=5;%設(shè)置小球的運動軌跡endift>2.8t=t+dt;a=sin(t-3);x1=6.1;y1=5.1;x3=4-2*sin(1.5*a);y3=5-2*cos(1.5*a);%設(shè)置大球的運動軌跡endset(head1,'xdata',x1,'ydata',y1);%設(shè)置球的運動set(head2,'xdata',x3,'ydata',y3);drawnow;end%</BT_Sphere>==============================================================%ExecutesonbuttonpressinBT_PictureShow.functionBT_PictureShow_Callback(hObject,eventdata,handles)%hObjecthandletoBT_PictureShow(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%<BT_PictureShow>==========================================================%=======================照片讀取=================================[x,cmap]=imread('E:\picture\走走走\100815\DSC00285.JPG');image(x);colormap(cmap);axisimageoff%</BT_PictureShow>=========================================================%ExecutesonbuttonpressinBT_Quit.functionBT_Quit_Callback(hObject,eventdata,handles)%hObjecthandletoBT_Quit(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%<BT_Quit>=================================================================close(gcf)%</BT_Quit>================================================================%functionNMI_Brownian_Callback(hObject,eventdata,handles)%hObjecthandletoNMI_Brownian(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%functionNMI_Sphere_Callback(hObject,eventdata,handles)%hObjecthandletoNMI_Sphere(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%functionNMI_PictureShow_Callback(hObject,eventdata,handles)%hObjecthandletoNMI

溫馨提示

  • 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論