MATLAB课程设计报告.docx

上传人:b****5 文档编号:4486994 上传时间:2022-12-01 格式:DOCX 页数:16 大小:192.46KB
下载 相关 举报
MATLAB课程设计报告.docx_第1页
第1页 / 共16页
MATLAB课程设计报告.docx_第2页
第2页 / 共16页
MATLAB课程设计报告.docx_第3页
第3页 / 共16页
MATLAB课程设计报告.docx_第4页
第4页 / 共16页
MATLAB课程设计报告.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

MATLAB课程设计报告.docx

《MATLAB课程设计报告.docx》由会员分享,可在线阅读,更多相关《MATLAB课程设计报告.docx(16页珍藏版)》请在冰豆网上搜索。

MATLAB课程设计报告.docx

MATLAB课程设计报告

MATLAB课程设计报告模板

 

《MATLAB课程设计》报告

 

设计题目:

函数的定积分与图像的保存

学生姓名:

陈秀

学生学号:

2009045444014

专业班级:

09通信工程(师范)

答辩时间:

2011年6月3日

指导教师:

冯明库

 

广东技术师范学院

电子与信息学院

一、设计目的及意义

运用函数quad8求已知函数在不同上下限内的定积分,并在坐标轴上显示出函数图形,利用这种方法有利于我们更加方便的计算定积分,且准确地画出函数图像。

二、设计任务及指标

(1)运用函数quad8求y=sin(x)^2在不同的区间的积分值;

(2)在坐标轴画出函数y=sin(x)^2的图像;

(3)实现保存函数图像的功能。

三、设计过程

3.1设计主界面介绍

建立一个默认的图形用户界面,保存为jifen.fig文件,在布局编辑器中布置控件:

(1)建立一个坐标轴对象,显示函数图像;

(2)建立三个按钮,分别用来求函数积分,保存图像和关闭程序;

(3)建立二个可编辑文本框,分别用来输入积分的上下限a和b;

(4)建立五个静态文本框,显示相应控件的提示和积分结果;

(5)建立一个panel控件。

界面设计如图1所示

图1控件布局

设置控件的相关属性:

(1)设置三个按钮的Tag标识分别为:

jifen_pushbutton,close_pushbutton,save_pushbutton;

(2)设置两个可编辑文本框的Tag的标识分别为:

a_edit,b_edit,用来输入积分的上下限;

(3)设置界面最底下的静态文本标签Tag标识为jifen_text,用来显示积分结果。

最终界面显示如图2所示

图2最终界面显示

3.2添加菜单

3.2.1添加文件菜单

建立一级菜单“文件”,在其下设置两个子菜单“积分”和“退出”。

“积分”的Tag设置为jifen_menu,“退出”的Tag设置为close_menu。

3.2.2添加选择菜单

建立一级菜单“选择”在其下设置三个子菜单“网格”,“边框”,“颜色”

(1)在“网格”下设置二个三级菜单“显示”,“隐藏”,“显示”的Callback设置为gridon,“隐藏“设置”为gridoff;

(2)在“边框”下设置二个三级菜单“显示”,“隐藏”,“显示”的Callback设置为boxon,“隐藏“设置”为boxoff;

(3)在“颜色”下设置三个三级菜单“蓝色”,“黄色”,“绿色”,“蓝色”的Callback设置为set(gcf,'Color','b'),“黄色”的Callback设置为set(gcf,'Color','y');“绿色”的Callback设置为set(gcf,'Color','g')。

如图3所示

图3添加菜单

3.3编写代码

(1)赋予a,b初始值

functionjifen_OpeningFcn(hObject,eventdata,handles,varargin)

%Thisfunctionhasnooutputargs,seeOutputFcn.

%hObjecthandletofigure

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%varargincommandlineargumentstojifen(seeVARARGIN)

%Choosedefaultcommandlineoutputforjifen

set(handles.b_edit,'String',0);

set(handles.a_edit,'String',1);

handles.output=hObject;

(2)运用函数quad8求函数在不同上下限内的定积分,其中a,b通过编辑文本框输入

functionjifen_pushbutton_Callback(hObject,eventdata,handles)

%hObjecthandletojifen_pushbutton(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

a=str2num(get(handles.a_edit,'String'));

b=str2num(get(handles.b_edit,'String'));

dx=0.01;x=a:

dx:

b;

y=sin(x).^2;

ff=inline('sin(x).^2','x');

q8_ax=quad8(ff,a,b);

set(handles.jifen_text,'String',num2str(q8_ax));

(3)在坐标轴上画出函数图形

plot(x,y,'r');

legend('f(x)',3);

title('sin(x).^2','Fontsize',10,'FontWeight','bold');

(4)赋予“保存”键保存坐标轴上图像的功能,并且图像可以保存为jpg和bmp的格式

functionpushbutton3_Callback(hObject,eventdata,handles)

%hObjecthandletopushbutton3(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

new_f_handle=figure('visible','off');

new_axes=copyobj(handles.axes1,new_f_handle);%axes1是GUI界面绘图的坐标系

set(new_axes,'units','default','position','default');

[filename,pathnamefileindex]=uiputfile({'*.jpg';'*.bmp'},'savepictureas');

if~filename

return

else

file=strcat(pathname,filename);

switchfileindex%根据不同的选择保存为不同的类型

case1

print(new_f_handle,'-djpeg',file);

case2

print(new_f_handle,'-dbmp',file);

end

end

delete(new_f_handle);

(4)赋予菜单栏中“积分”,“退出”功能

退出:

functionclose_menu_Callback(hObject,eventdata,handles)

Close

积分:

functionjifen_menu_Callback(hObject,eventdata,handles)

jifen_pushbutton_Callback(hObject,eventdata,handles)

四、结论及分析

(1)主界面

图4主界面

(2)输入a,b,运行结果

图5试运行

(3)运用图像保存功能

图6图像保存

保存结果:

图7保存的图像

五、设计体会

通过这次课程设计,我进一步了解MATLAB的程序设计过程,比较深层次地认识可视化图形用户界面设计的方法以及好处,并且复习了之前学习的MATLAB基础知识,虽说此次实训对我的难度较大,但也是一次很好的锻炼机会

参考文献:

[1]陈垚光,毛涛涛,王正林,王玲编著.精通MATLABGUI.北京:

电子工业出版社,2008.2.

程序清单:

functionvarargout=jifen(varargin)

%JIFENM-fileforjifen.fig

%JIFEN,byitself,createsanewJIFENorraisestheexisting

%singleton*.

%

%H=JIFENreturnsthehandletoanewJIFENorthehandleto

%theexistingsingleton*.

%

%JIFEN('CALLBACK',hObject,eventData,handles,...)callsthelocal

%functionnamedCALLBACKinJIFEN.Mwiththegiveninputarguments.

%

%JIFEN('Property','Value',...)createsanewJIFENorraisesthe

%existingsingleton*.Startingfromtheleft,propertyvaluepairsare

%appliedtotheGUIbeforejifen_OpeningFunctiongetscalled.An

%unrecognizedpropertynameorinvalidvaluemakespropertyapplication

%stop.Allinputsarepassedtojifen_OpeningFcnviavarargin.

%

%*SeeGUIOptionsonGUIDE'sToolsmenu.Choose"GUIallowsonlyone

%instancetorun(singleton)".

%

%Seealso:

GUIDE,GUIDATA,GUIHANDLES

%Copyright2002-2003TheMathWorks,Inc.

%Edittheabovetexttomodifytheresponsetohelpjifen

%LastModifiedbyGUIDEv2.502-Jun-201116:

17:

04

%Begininitializationcode-DONOTEDIT

gui_Singleton=1;

gui_State=struct('gui_Name',mfilename,...

'gui_Singleton',gui_Singleton,...

'gui_OpeningFcn',@jifen_OpeningFcn,...

'gui_OutputFcn',@jifen_OutputFcn,...

'gui_LayoutFcn',[],...

'gui_Callback',[]);

ifnargin&&ischar(varargin{1})

gui_State.gui_Callback=str2func(varargin{1});

end

ifnargout

[varargout{1:

nargout}]=gui_mainfcn(gui_State,varargin{:

});

else

gui_mainfcn(gui_State,varargin{:

});

end

%Endinitializationcode-DONOTEDIT

 

%---Executesjustbeforejifenismadevisible.

functionjifen_OpeningFcn(hObject,eventdata,handles,varargin)

%Thisfunctionhasnooutputargs,seeOutputFcn.

%hObjecthandletofigure

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%varargincommandlineargumentstojifen(seeVARARGIN)

%Choosedefaultcommandlineoutputforjifen

set(handles.a_edit,'String',0);

set(handles.b_edit,'String',1);

handles.output=hObject;

%Updatehandlesstructure

guidata(hObject,handles);

%UIWAITmakesjifenwaitforuserresponse(seeUIRESUME)

%uiwait(handles.figure1);

%---Outputsfromthisfunctionarereturnedtothecommandline.

functionvarargout=jifen_OutputFcn(hObject,eventdata,handles)

%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);

%hObjecthandletofigure

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Getdefaultcommandlineoutputfromhandlesstructure

varargout{1}=handles.output;

%---Executesonbuttonpressinjifen_pushbutton.

functionjifen_pushbutton_Callback(hObject,eventdata,handles)

%hObjecthandletojifen_pushbutton(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

a=str2num(get(handles.a_edit,'String'));

b=str2num(get(handles.b_edit,'String'));

dx=0.01;x=a:

dx:

b;

y=sin(x).^2;

ff=inline('sin(x).^2','x');

q8_ax=quad8(ff,a,b);

set(handles.jifen_text,'String',num2str(q8_ax));

plot(x,y,'r');

legend('f(x)',3);

title('sin(x)^2','Fontsize',10,'FontWeight','bold');

%---Executesonbuttonpressinsave_pushbutton.

functionsave_pushbutton_Callback(hObject,eventdata,handles)

%hObjecthandletosave_pushbutton(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

new_f_handle=figure('visible','off');

new_axes=copyobj(handles.axes1,new_f_handle);%axes1是GUI界面绘图的坐标系

set(new_axes,'units','default','position','default');

[filename,pathnamefileindex]=uiputfile({'*.jpg';'*.bmp'},'savepictureas');

if~filename

return

else

file=strcat(pathname,filename);

switchfileindex%根据不同的选择保存为不同的类型

case1

print(new_f_handle,'-djpeg',file);

case2

print(new_f_handle,'-dbmp',file);

end

end

delete(new_f_handle);

%---Executesonbuttonpressinclose_pushbutton.

functionclose_pushbutton_Callback(hObject,eventdata,handles)

%hObjecthandletoclose_pushbutton(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

close

functiona_edit_Callback(hObject,eventdata,handles)

%hObjecthandletoa_edit(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Hints:

get(hObject,'String')returnscontentsofa_editastext

%str2double(get(hObject,'String'))returnscontentsofa_editasadouble

%---Executesduringobjectcreation,aftersettingallproperties.

functiona_edit_CreateFcn(hObject,eventdata,handles)

%hObjecthandletoa_edit(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled

%Hint:

editcontrolsusuallyhaveawhitebackgroundonWindows.

%SeeISPCandCOMPUTER.

ifispc

set(hObject,'BackgroundColor','white');

else

set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));

end

functionb_edit_Callback(hObject,eventdata,handles)

%hObjecthandletob_edit(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Hints:

get(hObject,'String')returnscontentsofb_editastext

%str2double(get(hObject,'String'))returnscontentsofb_editasadouble

%---Executesduringobjectcreation,aftersettingallproperties.

functionb_edit_CreateFcn(hObject,eventdata,handles)

%hObjecthandletob_edit(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled

%Hint:

editcontrolsusuallyhaveawhitebackgroundonWindows.

%SeeISPCandCOMPUTER.

ifispc

set(hObject,'BackgroundColor','white');

else

set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));

end

%--------------------------------------------------------------------

functionjifen_menu_Callback(hObject,eventdata,handles)

%hObjecthandletojifen_menu(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructure

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 高中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1