MATLAB: Simple question with slider in GUI interface

editguiguidematlab guislider

I have a GUI interface with an edit text box (tag edit1) and a slider (tag slider 1). At a certain point of the program, a number is shown in the edit text box. What I want to do is to increase by 1 unit the number in edit1 when pressing the up arrow of the slider and decrease it by 1 unit when pressing the down arrow of the slider. What is the code to write into the function
function slider1_Callback(hObject, eventdata, handles)
? Thank you

Best Answer

Try this:
% Get string from edit box.
editBoxValue = get(handles.edit1, 'String');
% Convert string to number.
theNumber = str2double(editBoxValue);
% Increment the number.
theNumber = theNumber + 1;
% Send new number back into the edit box.
set(handles.edit1, 'String', theNumber);
You might want to consider use of a slider instead of edit boxes and keystrokes.