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

1 次查看(过去 30 天)
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);

采纳的回答

Walter Roberson
Walter Roberson 2015-10-7
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by