电子信息工程系实验报告
课程名称:MATLAB语言
酱驴肉的家常做法实验项目名称:MATLAB图形用户界面设计 实验时间:2010-5-8
班级: 姓名: 学号:
实验目的: 1、熟悉MATLAB的主要控件使用方法。
2、熟悉MATLAB的GUI设计流程。
实验环境:硬件配置( Pentium(R) 4 CPU 2.40GHz,1GB内存)
操作系统(Windows XP)
编程软件:MATLAB7.0
实验内容与结果:
使用MATLAB的GUI接口设计一个简单的计算器。
效果图:
程序源码部分函数及相关注释:
%0~9数字键及小数点按钮代码范例
%全局变量locaval用于存储用户输入的多位数值
%全局变量gloval2用于存储待处理的第二位数值
function pushbutton1_Callback(hObject, eventdata, handles)
global locaval;
a = get(handles.pushbutton1,'String');
locaval=strcat(locaval,a);
航拍中国新疆
1,'String',locaval);
global gloval2
gloval2=locaval;
guidata(hObject, handles);
%运算符按钮处理“+、-、*、\”范例
%全局变量flagnum存储运算符标志
%全局变量global1用于储存第一个待处理数值
function pushbutton10_Callback(hObject, eventdata, handles)
a = get(handles.pushbutton10,'String');
b = 1,'String');
1,'String',a);
牛肉煲汤global flagnum
global gloval1
global locaval
locaval=' ';
flagnum=1;
gloval1=b;
guidata(hObject, handles);
高中劝学原文及翻译
%取相反数按钮“+\-”代码
%算法实现:用零减去文本框现在的值,再赋值给文本框
function pushbutton14_Callback(hObject, eventdata, handles)
global locaval;
叠山理水locaval=str2num(locaval);
locaval=0-locaval;
locaval=num2str(locaval);
1,'String',locaval);
global gloval2
gloval2=locaval;
guidata(hObject, handles);
% 等号按钮运算实现
%根据flagnum运算标志用switch决策语句实现相应计算
%需注意相应数据类型的转化
function pushbutton17_Callback(hObject, eventdata, handles)
global flagnum
global gloval1
global gloval2
global locaval
locaval=' ';
gloval1=str2num(gloval1);
gloval2=str2num(gloval2);
ca1=gloval1/gloval2;
ca2=gloval1*gloval2;
ca3=gloval1-gloval2;
ca4=gloval1+gloval2;
ca1=num2str(ca1);
ca2=num2str(ca2);
ca3=num2str(ca3);
纯洁的心
ca4=num2str(ca4);
switch flagnum;
ca 1
1,'String',ca1);
ca 2
1,'String',ca2);
ca 3
1,'String',ca3);
ca 4
1,'String',ca4);
作业的重要性
end
guidata(hObject,handles)
% BackSpace按钮函数
%算法实现:MATLAB是用矩阵存储数据的,相应的可以取文本框的前N-1实现其功能
function pushbutton19_Callback(hObject, eventdata, handles)
textString = 1,'String');
if(strcmp(textString,'0.')==1)
1,'String','0.') ;
el
ss=char(textString);
l=length(textString);
textString=ss(1:l-1);
1,'String',textString)
end
guidata(hObject,handles)
%C清除按钮函数
%把全局变量locaval清零
function pushbutton20_Callback(hObject, eventdata, handles)
global locaval
locaval=' ';
1,'String','0.');
guidata(hObject,handles)
%开平方函数
function pushbutton22_Callback(hObject, eventdata, handles)
textString = 1,'String');
textString=str2num(textString);
textString=sqrt(textString);
心声的意思
textString=num2str(textString);
1,'String',textString);
locaval=' ';
guidata(hObject,handles)
%取1/x函数
function pushbutton24_Callback(hObject, eventdata, handles)
global locaval
locaval=str2num(locaval);
locaval=1/locaval;
1,'String',locaval);
locaval=' ';
guidata(hObject,handles)
实验心得:
!、通过MATLAB简单计算器的设计,初步了解了关于MATLAB图形用户界面的部分控件的使用方法。
2、MATLAB的GUI提供的很多实用的控件,方便用于设计属于自己的图形界面。
源码:
function varargout = bt0(varargin)
% BT0 M-file for bt0.fig
% BT0, by itlf, creates a new BT0 or rais the existing
% singleton*.
%
% H = BT0 returns the handle to a new BT0 or the handle to
% the existing singleton*.
%
% BT0('Property','Value',...) creates a new BT0 using the
% given property value pairs. Unrecognized properties are pasd via
% varargin to bt0_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% BT0('CALLBACK') and BT0('CALLBACK',hObject,...) call the
% local function named CALLBACK in BT0.M with the given input
% arguments.
%
% *See GUI Options on GUIDE's Tools menu. Choo "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the respon to help bt0
% Last Modified by GUIDE v2.5 04-May-2010 14:01:00
% Begin initialization code - DO NOT EDIT
global gloval1;
global gloval2;
global flagnum;
global locaval;
gui_Singleton = 1;