How do I update my slider using an edit text?

18 visualizzazioni (ultimi 30 giorni)
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 Commento
Paul
Paul il 8 Ago 2014
Modificato: Paul il 8 Ago 2014
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

Accedi per commentare.

Risposta accettata

Evan
Evan il 8 Ago 2014
Modificato: Evan il 8 Ago 2014
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)

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by