Assign values to an "Editor Text" box using manual input or a push button

2 views (last 30 days)
I want to allow user to insert different numbers in an editor text box to be used further in the code. But I also want to add a push button to restore a default value to that parameter (and show that number in the edit text box) when needed. How can I do this? My callback functions are as follows.
function GLP_fsize_val_Callback(hObject, eventdata, handles)
handles.GLP_fsize_val=str2double(get(hObject,'String'));
guidata(hObject, handles);
[similar function for sigma]
function Default_GLF_Callback(hObject, eventdata, handles)
set(handles.GLP_fsize_val,'string',handles.defaults.GLP_fsize_val);
set(handles.GLP_sigma_val,'string',handles.defaults.GLP_fsize_val);
guidata(hObject, handles);

Accepted Answer

Walter Roberson
Walter Roberson on 7 Oct 2015
You currently have
function GLP_fsize_val_Callback(hObject, eventdata, handles)
handles.GLP_fsize_val=str2double(get(hObject,'String'));
guidata(hObject, handles);
This is replacing the stored handle to the fsize edit callback with the numeric equivalent to the string stored in the callback. That would invalidate the use of the stored handle elsewhere.
There is no need to have a GLP_fsize_val_Callback callback at all unless you want to do error checking on the string the user entered. Callbacks for edit boxes allow you to do error checking, and they allow you to do other actions (like calculations) when the user enters data. You have your Apply button so you do not want calculations done when the user enters data, so the only point in having a callback for the edit box would be error checking.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!