How to retrieve data entered in an edit box

I have an edit box in my GUI. User inputs a number into the editbox and then pushes a pushbutton. when the pushbutton is pressed an external function is called. for the external function i need the number entered in the editbox. How can i used 'handles' to retrieve the data input in the edit box?

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 11 Mar 2013
Modifié(e) : Azzi Abdelmalek le 11 Mar 2013
s=str2double(get(handles.editboxname,'string'))
% editboxname is the tag of your edit box.

9 commentaires

would I have to define 's' somewhere else, other than when I am using it in my callback function. Do i need to define s=0 before my opening function for example
Azzi Abdelmalek
Azzi Abdelmalek le 11 Mar 2013
Modifié(e) : Azzi Abdelmalek le 11 Mar 2013
If you want to set it to 0 in your opening function
set(handles.editboxname,'string','0')
I set it as 0 just before my opening function. my editbox is called EnterSpeed. I have made my GUI three times I keep debugging but i am still coming up with errors for e.g:-
??? Undefined variable "handles" or class "handles.EnterSpeed".
Error in ==> NEWSTALLGUI at 46
set(handles.EnterSpeed,'string','0');
>>
Azzi Abdelmalek
Azzi Abdelmalek le 11 Mar 2013
Modifié(e) : Azzi Abdelmalek le 11 Mar 2013
How did you create the name EnterSpeed ?
% --- 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);
I I have set EnterSpeed as 0 in my opening function. When I created the editbox I changed it into EnterSpeed. Do you think it will be easier to work with name such as 'editbox'
Azzi Abdelmalek
Azzi Abdelmalek le 11 Mar 2013
No this have nothing to do with the name, I am not sure that the name is EnterSpeed. When you click on view callback of your editbox, which name are you seeing?
I am not sure what you mean exactly tbh.
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'));
This is my callback code for my editbox
Azzi Abdelmalek
Azzi Abdelmalek le 11 Mar 2013
Modifié(e) : Image Analyst le 11 Mar 2013
The code
user_speed=str2double(get(handles.EnterSpeed,'string'));
You should put it in the pushbutton callback, NOT the edit field callback.
thankyou that has done the trick

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by