So my edit text is able to change the value of my slider, but only after the slider is clicked on, is there any way that the slider could be updated continuously or after I hit enter? Here is my code in the slider callback:
val=str2num (get (handles.edit1, 'String'));
set(handles.slider1, 'Value', val);

댓글 수: 1

Paul
Paul 2014년 8월 8일
편집: Paul 2014년 8월 8일
I would suggest that you create a generic callback function, and give each of your objects a Tag with an appropriate name.
In this case, the edit box would have
set(handles.edit1,'Tag','handles.edit')
and slider would be
set(handles.slider1,'Tag','handles.slider1')
Assign a generic callback to each
set(handles.edit1,'Callback',@genericCB)
set(handles.slider1,'Callback',@genericCB)
Now you create the generic callback that reads the Tag
function genericCB(src,eventdata)
handleLink = get(src,'Tag')
if any(regexp(handleLink,'edit1'))
% The edit1 object was called, update slider1
elseif any(regexp(handleLink,'slider1'))
% The slider1 object was called, update edit1
end
Edit: When you enter a value into the edit box, the callback will not be called until you click outside of the edit box or press on the keyboard. If you want the slider to update as you are typing, I believe you'll need to create a java object instead of a uicontrol object

댓글을 달려면 로그인하십시오.

 채택된 답변

Evan
Evan 2014년 8월 8일
편집: Evan 2014년 8월 8일

3 개 추천

To make the slider update when the editbox is updated, put the update code in the editbox callback
function myEditBox_Callback(hObject,eventdata,handles)
val = str2double(get(hObject,'String'));
set(handles.slider1,'Value',val);
guidata(hObject,handles)
And then, in the slider's callback:
function slider1_Callback(hObject,eventdata,handles)
val = get(hObject,'Value');
set(handles.myEditBox,'String',num2str(val));
guidata(hObject,handles)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

2014년 8월 8일

댓글:

Jo
2021년 6월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by