How to Set Slider Handles in MATLAB

Written by sean hill
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Set Slider Handles in MATLAB
Learn how to add a slider object to a Matlab GUI (Comstock/Comstock/Getty Images)

The MATLAB graphical user interface, or GUI, tool allows users to create a user interface without having to code the complete program from scratch. MATLAB allows users to choose the objects they want from toolbox of pre-coded GUI objects such as sliders, push buttons, check boxes and radio buttons. Users can then drag these objects onto their user interface template and customise the objects with a property inspector or by tweaking the pre-made code.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Open MATLAB, and type "guide" in the command window.

  2. 2

    Select the GUI you would like to open, and click "OK." Otherwise, click "Blank GUI" if you would like to create a new GUI.

  3. 3

    Click the icon with the horizontal bar to add the "Slider" object to your GUI.

  4. 4

    Double-click the "Slider" object, and when the property inspector appears, change values next to "Max" and "Min" to the numerical limits by which you would like the slider to be bounded. For example, 0 and 100 can be a Min and Max, respectively.

  5. 5

    Change the text next to "Tag" to "slider1."

  6. 6

    Click the "Save" icon in the top-left part of your screen.

  7. 7

    Open the code for the GUI by clicking on the icon with the paper and pencil in the GUI editor window.

  8. 8

    Click the "f" icon in the m-file window. Select "slider1_Callback" from the drop-down menu.

  9. 9

    Add the following code to the callback function to set the slider position to a given value:


    Note that "n" can be any numerical value and can even be a number obtained from other objects or functions in the GUI.

Tips and warnings

  • To set the slider position to a value obtained from another object, insert the following code: "n = get(handles.Handlename,'Value');". "Handlename" should be the name of the other object (e.g. "textbox1"). You may have to convert "n" from a string to a number to get the function to work. In that case, use the following code:
  • "set(handles.slider1,'Value',str2num(n));
  • Make sure to add a semicolon to the end of every line of code in your m-file. Otherwise, errors will result.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.