MATLAB: How to make a text box in GUI that updates immediately when slider is moved

guiguideMATLAB

I apologize if this is easy to figure out, but I'm exhausted on this Friday evening. I'm new to making GUIs. I want to have a GUI in which there is a slider and whenever the user changes the slider position, a text box immediately takes the value in the slider and displays it. In other words, I don't want there to be any guesses as to what value the slider is at, I want it to be displayed as soon as the slider position is changed. How do I make this textbox update the value of the slider dynamically like that?
Thanks!

Best Answer

Alexei - see the solution from make GUI slider behave like iOS frame scroller which will tell you how to create a continuous value change listener for the slider. The only thing that ail be missing is how to update the text box which you can do by just modifying the slider1ContValCallback (from the link) as
function slider1ContValCallback(hFigure,eventdata)
% test it out - get the handles object and write the current value
% to the edit box
handles = guidata(hFigure);
sliderValue = get(handles.slider1,'Value');
set(handles.text1,'String',num2str(sliderValue));
The above assumes that text1 is the tag for the text box that you wish to update, and that slider1 is the tag for your slider.
Try it out and see what happens!