杭电实践:MATLAB在电子信息中的应用(上机练习4)

GUI做一个简易计算器

function varargout = untitled(varargin) % UNTITLED MATLAB code for untitled.fig %      UNTITLED, by itself, creates a new UNTITLED or raises the existing %      singleton*. % %      H = UNTITLED returns the handle to a new UNTITLED or the handle to %      the existing singleton*. % %      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local %      function named CALLBACK in UNTITLED.M with the given input arguments. % %      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the %      existing singleton*.  Starting from the left, property value pairs are %      applied to the GUI before untitled_OpeningFcn gets called.  An %      unrecognized property name or invalid value makes property application %      stop.  All inputs are passed to untitled_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 untitled % Last Modified by GUIDE v2.5 28-Nov-2021 17:32:09 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name',       mfilename, ...                    'gui_Singleton',  gui_Singleton, ...                    'gui_OpeningFcn', @untitled_OpeningFcn, ...                    'gui_OutputFcn',  @untitled_OutputFcn, ...                    'gui_LayoutFcn',  [] , ...                    'gui_Callback',   []); if nargin && ischar(varargin{1})     gui_State.gui_Callback = str2func(varargin{1}); end if nargout     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else     gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before untitled is made visible. function untitled_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 untitled (see VARARGIN) % Choose default command line output for untitled handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = untitled_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 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 function edit3_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 edit3_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 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 = get(handles.edit2,'String'); set(handles.edit1,'String',''); set(handles.edit2,'String',''); 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,'*'); 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,'/'); 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,'-'); 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,'+'); 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'); res = eval(textString); set(handles.edit2,'String',res); 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'); res1 = eval(textString); res = sqrt(res1); set(handles.edit2,'String',res); 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) close(gcf); function edit4_Callback(hObject, eventdata, handles) % hObject    handle to edit4 (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 edit4 as text %        str2double(get(hObject,'String')) returns contents of edit4 as a double % --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % hObject    handle to edit4 (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 % -------------------------------------------------------------------- function menu1_Callback(hObject, eventdata, handles) % hObject    handle to menu1 (see GCBO) % eventdata  reserved - to be defined in a future version of MATLAB % handles    structure with handles and user data (see GUIDATA) p = imread('C:\Users\hurricane\Desktop\matlab在电子信息中的应用\football.jfif'); figure(1); imshow(p); % -------------------------------------------------------------------- function menu2_Callback(hObject, eventdata, handles) % hObject    handle to menu2 (see GCBO) % eventdata  reserved - to be defined in a future version of MATLAB % handles    structure with handles and user data (see GUIDATA) p = imread('C:\Users\hurricane\Desktop\matlab在电子信息中的应用\football.jfif'); figure(1); imshow(p); [x0,y0] = ginput; [x1,y1] = ginput;  figure(2) B = plot(x0,y0,'*k',x1,y1,'*k');  picture_1 = imcrop(p,[x0,y0,abs(x0-x1),abs(y0-y1)]);  %切割图像,起始坐标点(x0,y0)截取到终止坐标点(x1,y1) % -------------------------------------------------------------------- function menu3_Callback(hObject, eventdata, handles) % hObject    handle to menu3 (see GCBO) % eventdata  reserved - to be defined in a future version of MATLAB % handles    structure with handles and user data (see GUIDATA) p = imread('C:\Users\hurricane\Desktop\matlab在电子信息中的应用\football.jfif'); figure(1); imshow(p); [x0,y0] = ginput; [x1,y1] = ginput;  figure(2) B = plot(x0,y0,'*k',x1,y1,'*k');  picture_1 = imcrop(p,[x0,y0,abs(x0-x1),abs(y0-y1)]);  %切割图像,起始坐标点(x0,y0)截取到终止坐标点(x1,y1) saveas(picture_1, 'C:\Users\hurricane\Desktop\matlab在电子信息中的应用\picture_1', 'jpg');%将图片保存在程序所在文件夹中

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空