How do I update my slider using an edit text?
13 次查看(过去 30 天)
显示 更早的评论
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
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
2014-8-8
编辑:Evan
2014-8-8
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!