MATLAB Creating Graphical User Interfaces

(Barry) #1

9 Examples of GUIDE UIs


function update_listbox(handles)
vars = evalin('base','who');
set(handles.listbox1,'String',vars)

The function input argument is the handles structure set up by the GUIDE. This
structure contains the handle of the list box, as well as the handles of all other
components in the UI.

The callback for the Update Listbox push button also calls update_listbox.

Read Selections from List Box


To use the UI, select two variables from the workspace and then choose one of three plot
commands to create a graph: plot, semilogx, or semilogy.

No callback for the list box exists in the code file. One is not needed because the plotting
actions are initiated by push buttons.

Enable Multiple Selection

Use the Property Inspector to set these properties on the list box. To enable multiple
selection in a list box, change the default values of the Min and Max properties so that
Max - Min > 1.

Selecting Multiple Items

List box selection follows the standard for most systems:


  • Ctrl+click left mouse button — noncontiguous multi-item selection

  • Shift+click left mouse button — contiguous multi-item selection


Use one of these techniques to select the two variables required to create the plot.

Return Variable Names for the Plotting Functions

The local function, get_var_names, returns the two variable names that are selected
when you click one of the three plotting buttons. The function does these tasks:


  • Gets all the items in the list box from the String property.

  • Gets the indices of the selected items from the Value property.

Free download pdf