Matlab comes with a built-in graphical user interface editor that you can use to create GUI without having to code everything from scratch. The editor lets you select objects from a palette of precoded GUI objects, such as sliders, check boxes and push buttons. After you've placed a pre-coded object into a GUI, you can customize the object with the property inspector and by tweaking code.
Type guide in the Matlab command window and press Enter.
Open an existing GUI project from the list of saved projects. Click the slider icon on the objects palette to add a slider to your GUI.
Double-click the slider object to open the property inspector. Change Tag to your preferred name for the slider.
Click the Save icon in the GUI editor, and your GUI's code should appear. If not, click the pencil and paper icon to open the code.
Scroll down the code until you see the slider1_Callback function.
Type n = get(handles.Handlename,'Value'); below the last line of the slider1_Callback function. "Handlename" should be the name of another object, such as a text box, at whose value you want to set the slider.
Type set(handles.slider1,'Value',n)); below the last line of the line you typed previously to pass the value from the other handle to your slider. Set your slider at that value.
Tips & Warnings
- Always add a semicolon at the end of every complete line of code.