文章目录

  • 1.先打开matlab新建GUI文件
  • 2.选择路径(左边是默认的不用改)
  • 3.此时界面会弹出一个小框
  • 4.建立计算器界面(贴上我设计的界面,不许嘲笑我的设计)
  • 5.细致讲解一下,这里的按键和显示框的是怎么实现的
  • 6.把界面雏形做出之后,我们需要去实现计算器的操作
  • 7.初始化操作

1.先打开matlab新建GUI文件

2.选择路径(左边是默认的不用改)

然后点击ok

3.此时界面会弹出一个小框

4.建立计算器界面(贴上我设计的界面,不许嘲笑我的设计)

5.细致讲解一下,这里的按键和显示框的是怎么实现的

A.显示框: 选择edit text

在右边屏幕拉取即可

如图所示,新建两个即可,左边作为输入屏,右边作为输入结果的显示屏
双击该框,弹出一个窗口,窗口下拉,里面有该显示框的属性

string值为显示框显示的值
Tag为显示框的名字
(现在这个计算器需要显示框和输出框,如果没有新建其他的edit框,默认新建的第一个edit框的名字为edit1,第二个为edit2)

B.数字按钮和字符按钮
点击push button 新建按钮,需要几个建几个

双击之后在string那一栏改成你所需要的按钮

回车之后,如图所示

6.把界面雏形做出之后,我们需要去实现计算器的操作

A.首先改0~9的数字键(需要点击后在edit1上显示该数字)
右键点击你需要改的button之后会出现一个窗口选择view callbacks->callback,然后会打开一个函数,蓝色字体所在的位置是该button所在的位置的代码

按照这个方式将自己的代码改成自己所需要的数字
handles.后面加的是自己所需要将显示的文本框的名字

textString = get(handles.edit1,‘String’);
textString = strcat(textString,‘6’);
set(handles.edit1,‘String’,textString);
guidata(hObject, handles);

B.对于计算符号

textString = get(handles.edit1,‘String’);
textString = strcat(textString,’+’);
set(handles.edit1,‘String’,textString);
guidata(hObject, handles);

加减乘除只需用换一下就好
C.对于AE操作

textString = get(handles.edit1,‘String’);
textString = get(handles.edit2,‘String’);
set(handles.edit1,‘String’,’’);
set(handles.edit2,‘String’,’’);
guidata(hObject, handles);

D.对于back操作

textString=get(handles.edit1,‘String’);
as=char(textString);
n=length(textString);
textString=as(1:n-1);
set(handles.edit1,‘String’,textString)
guidata(hObject, handles);

E.退出操作

close(gcf);

7.初始化操作

A.需要对edit1和edit2进行初始化,使代码运行时,文本框里为空白(需要在opening里改函数)

set(handles.edit1,‘string’,’’);
set(handles.edit2,‘string’,’’);

B.需要将edit1的结果在edit2中显示出来(需要改计算那个button的函数值)

textString = get(handles.edit1,‘String’);
aa = eval(textString);
set(handles.edit2,‘String’,aa);
guidata(hObject, handles);

使其显示在edit2上
点击运行即可实现计算器。

function varargout = text2(varargin)
% TEXT2 MATLAB code for text2.fig
%      TEXT2, by itself, creates a new TEXT2 or raises the existing
%      singleton*.
%
%      H = TEXT2 returns the handle to a new TEXT2 or the handle to
%      the existing singleton*.
%
%      TEXT2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TEXT2.M with the given input arguments.
%
%      TEXT2('Property','Value',...) creates a new TEXT2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before text2_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to text2_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help text2% Last Modified by GUIDE v2.5 28-May-2018 19:45:49% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...'gui_Singleton',  gui_Singleton, ...'gui_OpeningFcn', @text2_OpeningFcn, ...'gui_OutputFcn',  @text2_OutputFcn, ...'gui_LayoutFcn',  [] , ...'gui_Callback',   []);
if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT% --- Executes just before text2 is made visible.
function text2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to text2 (see VARARGIN)% Choose default command line output for text2
set(handles.edit1,'string','');
set(handles.edit2,'string','');handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes text2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.
function varargout = text2_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)% Get default command line output from handles structure
varargout{1} = handles.output;function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');
end% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
aa = eval(textString);
set(handles.edit2,'String',aa);
guidata(hObject, handles);function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');
end% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'7');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'8');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'9');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'4');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'5');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'6');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'1');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'2');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'3');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'0');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'+');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = get(handles.edit2,'String');
set(handles.edit1,'String','');
set(handles.edit2,'String','');
guidata(hObject, handles);% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'-');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'*');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'/');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton17 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'4');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton18 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'7');
set(handles.edit1,'String',textString);
guidata(hObject, handles);% --- Executes on button press in pushbutton19.
function pushbutton19_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton19 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close(gcf);% --- Executes on button press in pushbutton20.
function pushbutton20_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton20 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString=get(handles.edit1,'String');
as=char(textString);
n=length(textString);
textString=as(1:n-1);
set(handles.edit1,'String',textString)
guidata(hObject, handles);% --- Executes on button press in pushbutton21.
function pushbutton21_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton21 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
textString = get(handles.edit1,'String');
textString = strcat(textString,'.');
set(handles.edit1,'String',textString);
guidata(hObject, handles);

MATLAB GUI实现计算器(设计)相关推荐

  1. 【信号处理】基于Matlab GUI数字均衡器设计,源码附上

    [信号处理]基于Matlab GUI数字均衡器设计,源码附上 数字均衡器是一种常用于音频信号处理的技术,可以有效地补偿声音中的频率失真,提高音质.在这篇文章中,我们将介绍如何使用Matlab GUI进 ...

  2. Matlab gui用户图形设计界面学习笔记(一)——单个界面的菜单设计

    Matlab gui用户图形设计界面学习笔记(一)--单个界面的菜单设计 弹出式菜单(pop-up menu)和下拉列表框(listbox) 实现功能:pop menu最初为 "请选择省份& ...

  3. MATLAB GUI图形界面设计一个学生管理系统

    设计一个简单的学生成绩管理程序,包含如下功能: 1.可创建不少于100名学生成员: 2.每名成员的记录包括:学号.姓名.专业和5门课程的成绩:  3.能够实现添加.删除.修改学生成员:(增加非法字符警 ...

  4. matlab gui教程 计算器,matlab gui编写的计算器程序

    首先应设计好计算器的GUI界面 如下图所示,然后分别设置'数据1'.'数据2'.'计算结果'的tag值为num1.num2和shuchu 当然你要是愿意也可以定义加减乘除按钮的tag属性,tag属性值 ...

  5. matlab能做什么设计,Matlab GUI是什么(设计实例)

    MatlabGUI是什么 MATLABGUI为图形用户界面(GraphicalUserInterface,简称GUI,又称图形用户接口)是指采用图形方法显示的计算机操作用户界面,是MATLAB用户可视 ...

  6. 重磅:分享Matlab GUI和App计算器源代码(后续)

    重磅:分享Matlab GUI和App计算器源代码(后续) 继上次推文<重磅:分享Matlab GUI和App计算器源代码 >后,按照朋友们的需求,增加了利用GUI和APP设计工具(gui ...

  7. 基于matlab的脑瘤mr图像处理_基于Matlab GUI的医学图像处理课程虚拟实验平台设计...

    论文写作指导:请加QQ229366758 摘 要:针对医学生工程技术缺乏的状况,分析医学生学习医学图像处理存在的困难,提出利用Matlab图像处理工具和简单的GUI界面,设计和构建包含医学图像处理教学 ...

  8. 用matlab做音乐仿真,Matlab课程设计报告--MATLAB GUI的音乐键盘仿真

    Matlab课程设计报告--MATLAB GUI的音乐键盘仿真 1 MATLAB MATLAB 实践实践 课程设计课程设计 目目 录录 1.1.设计目的设计目的3 3 2.2.题目分析题目分析3 3 ...

  9. matlab音乐键盘模拟,Matlab课程设计报告--MATLAB GUI的音乐键盘仿真

    Matlab课程设计报告--MATLAB GUI的音乐键盘仿真 < MATLAB 实践 > 课程设计 目 录 1.设计目的-------------------3 2.题目分析------ ...

最新文章

  1. 【首轮官宣】中国肠道大会姊妹盛会,GUT 2022正式启航!
  2. python【Matlibplot绘图库】绘制用于学术论文投稿的黑白图片
  3. Uva10294 Arif in Dhaka (置换问题)
  4. 【Python基础】Matplotlib 实操干货,38个案例带你从入门到进阶!
  5. golang常用库:字段参数验证库-validator使用
  6. 使用verilog设计实现QR分解
  7. 知道cve编号怎么搜poc_想在海南买房不知道该怎么选?快来看看这些热搜楼盘吧!...
  8. 多线激光雷达遇到的问题
  9. 数据挖掘建模过程——思维导图
  10. Awesome Blockchain 区块链技术导航
  11. what is Personnel
  12. DDCTFRre3-虚拟指令分析
  13. 新手学习电脑知识的一些方法
  14. RI-TRP-DR2B 32mm 玻璃应答器|CID载码体标签在半导体行业重复利用之检测方法
  15. hostapd配置解析
  16. 寻找全排列的下一个数
  17. 戴尔7060安服务器系统,戴尔7060装win7系统教程和BIOS设置方法(USB驱动可用)
  18. 集群搭建系列(八)Kafka
  19. K8S有状态静态Pod经典示例
  20. hdu 6106 Classes (二分)

热门文章

  1. 多机房动环状态网络触摸屏监控解决方案
  2. ios的AutoresizingMask
  3. 3种SAT数学解题方法介绍
  4. theano 报错WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLA
  5. linux驱动开发 - 10_阻塞和非阻塞 IO
  6. 全国程序员工资新统计,“高危”行业就这收入?
  7. 关于项目实施的一些想法
  8. 怎么给pdf文件加密,pdf设置密码步骤
  9. Redis对于过期key的处理
  10. 【wit】学生考试规范要求