Specifications
Accessing Workspace Variables from a List Box
5-25
•Delete the string assigned to the list box Callback property.
View the Layout and Application M-File
Use 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. The first link adds a directory to your
MATLAB path.
Click here to display this GUI in the Layout Editor.
Click here to display the application 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. The following
subfunction added to the application 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
application 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.