Assign values to an "Editor Text" box using manual input or a push button
조회 수: 3 (최근 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149855/image.jpeg)
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);
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!