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
Open MATLAB, and type "guide" in the command window.
Select the GUI you would like to open, and click "OK." Otherwise, click "Blank GUI" if you would like to create a new GUI.
Click the icon with the horizontal bar to add the "Slider" object to your GUI.
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.
Change the text next to "Tag" to "slider1."
Click the "Save" icon in the top-left part of your screen.
Open the code for the GUI by clicking on the icon with the paper and pencil in the GUI editor window.
Click the "f" icon in the m-file window. Select "slider1_Callback" from the drop-down menu.
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:
- Make sure to add a semicolon to the end of every line of code in your m-file. Otherwise, errors will result.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for