Specifications

5 GUI Applications
5-16
Delete the string assigned to the list box Callback property.
View Completed Layout and Its GUI M-File
If you are reading this in the MATLAB Help browser, you can click the
following links to display the GUIDE Layout Editor and the MATLAB Editor
with a completed version of this example. This enables you to see the values of
all component properties and to understand how the components are
assembled to create the GUI. You can also see a complete listing of the code
that is discussed in the following sections.
Note The following links execute MATLAB commands and are designed to
work within the MATLAB Help browser. If you are reading this online or in
PDF, you should go to the corresponding section in the MATLAB Help
Browser to use the links.
Click here to display this GUI in the Layout Editor.
Click here to display the GUI M-file in the editor.
Reading Workspace Variables
When the GUI initializes, it needs to query the workspace variables and set the
list box
String property to display these variable names. Adding the following
subfunction to the GUI M-file accomplishes this using
evalin to execute the
who command in the base workspace. The who command returns a cell array of
strings, which are used to populate the list box.
function update_listbox(handles)
vars = evalin('base','who');
set(handles.listbox1,'String',vars)
The function’s input argument is the handles structure generated by the GUI
M-file. This structure contains the handle of the list box, as well as the handles
all other components in the GUI.
The callback for the
Update Listbox push button also calls update_listbox.