Edit text as input in GUI

Hello,
I have a GUI (created in GUIDE), and I want to be able to have a edit text that I assign values to it and when I hit on other buttons, that value will be used. The problem is that it's not actually a number, but a set of numbers, i.e:
1:2:33
or even multiple inputs such as:
1:5,22:52, 66:68 etc
I have tried the below code but didn't work
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a
double
handles.back= str2double(get(hObject,'String'))
any good suggestions? TYIA

回答 (1 件)

Image Analyst
Image Analyst 2013 年 4 月 11 日

0 投票

Don't do anything in the edit field callback. Do everything in the button callbacks where you want to use the edit field. For example in the callback for button1:
editText = get(handles.edit3,'String');
% Now parse it with sscanf(), allwords, or whatever.
myNumberArray = ......% whatever...
Find allwords here: allwords()

7 件のコメント

tony karamp
tony karamp 2013 年 4 月 11 日
so the edit3 callback function will remain empty?
Image Analyst
Image Analyst 2013 年 4 月 12 日
Yes, or maybe some default code. You don't need to add any code of your own to that function.
tony karamp
tony karamp 2013 年 4 月 12 日
I add the code then as it is?
editText = get(handles.edit3,'String');
myNumberArray = sscanf(editText);
Thanks!
Image Analyst
Image Analyst 2013 年 4 月 12 日
You're welcome. sscanf() usually takes a string and a format specifier. Mark as Accepted if we're all done here.
tony karamp
tony karamp 2013 年 4 月 12 日
I made the modifications to the mfile, but when I try to run the GUI I get an error saying:
Error using ==> sscanf
Not enough input arguments.
Error in ==> DSSGUI>startbutton_Callback at 156
fharmArray = sscanf(FeditText);
Error in ==> gui_mainfcn at 66
feval(varargin{:});
Error in ==> DSSGUI at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)DSSGUI('startbutton_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
tony karamp
tony karamp 2013 年 4 月 12 日
I used the eval function after all and works perfectly...

サインインしてコメントする。

カテゴリ

質問済み:

2013 年 4 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by