MATLAB guide例子

1、guide排列后

MATLAB guide例子_第1张图片
MATLAB guide例子_第2张图片
String-文本框显示
Style-类型
Tag-保存显示名字
TooltipString-鼠标移动至此显示提示

2、保存后

function varargout = caculate1(varargin)
% CACULATE1 MATLAB code for caculate1.fig
%      CACULATE1, by itself, creates a new CACULATE1 or raises the existing
%      singleton*.
%
%      H = CACULATE1 returns the handle to a new CACULATE1 or the handle to
%      the existing singleton*.
%
%      CACULATE1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CACULATE1.M with the given input arguments.
%
%      CACULATE1('Property','Value',...) creates a new CACULATE1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before caculate1_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to caculate1_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 caculate1

% Last Modified by GUIDE v2.5 18-Mar-2020 15:59:18

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @caculate1_OpeningFcn, ...
                   'gui_OutputFcn',  @caculate1_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 caculate1 is made visible.
function caculate1_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 caculate1 (see VARARGIN)

% Choose default command line output for caculate1
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes caculate1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = caculate1_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 edit_add1_Callback(hObject, eventdata, handles)
% hObject    handle to edit_add1 (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 edit_add1 as text
%        str2double(get(hObject,'String')) returns contents of edit_add1 as a double


% --- Executes during object creation, after setting all properties.
function edit_add1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_add1 (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 edit_add2_Callback(hObject, eventdata, handles)
% hObject    handle to edit_add2 (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 edit_add2 as text
%        str2double(get(hObject,'String')) returns contents of edit_add2 as a double


% --- Executes during object creation, after setting all properties.
function edit_add2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_add2 (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 caculate.
function caculate_Callback(hObject, eventdata, handles)
% hObject    handle to caculate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% hObject-可计算的柄
% eventdata -保留-将在未来版本的MATLAB中定义
% handles-具有句柄和用户数据的结构

3、在回调函数% — Executes on button press in caculate.下操作

num1=str2double(get((handles.edit_add1),'String'));
num2=str2double(get((handles.edit_add2),'String'));
r=num1+num2;
r=num2str(r);
set(handles.result,'String',r);
guidata(hObject, handles);

1、str2double-将字符串转换为双精度值
2、get((handles.edit_add2),‘String’)得到edit_add2里面的String
3、num2str -将数字转换为字符表示
4、guidata(hObject, handles); 更新句柄结构

MATLAB guide例子_第3张图片

你可能感兴趣的:(Matlab,matlab)