我的 GUI 中有一个编辑框。用户在编辑框中输入一个数字,然后按下按钮。当按下按钮时,调用外部函数。对于外部函数,我需要在编辑框中输入的数字。我如何使用“句柄”来检索编辑框中的数据输入?
这是我的打开功能的代码
% --- Executes just before NEWSTALLGUI is made visible.
function NEWSTALLGUI_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 NEWSTALLGUI (see VARARGIN)
% Choose default command line output for NEWSTALLGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.EnterSpeed,'string','0');
% UIWAIT makes NEWSTALLGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
这是我的编辑框的代码
function EnterSpeed_Callback(hObject, eventdata, handles)
% hObject handle to EnterSpeed (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 EnterSpeed as text
% str2double(get(hObject,'String')) returns contents of EnterSpeed as a double
user_speed=str2double(get(handles.EnterSpeed,'string'));
这是我的按钮的代码
% --- Executes on button press in Calculate.
function Calculate_Callback(hObject, eventdata, handles)
% hObject handle to Calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Newfunction(user_speed);