Creating Graphical User Interfaces |
Reading the Selections from the List Box
This GUI requires the user to select two variables from the workspace and then choose one of three plot commands to create the graph: plot
, semilogx
, or semilogy
.
Enabling Multiple Selection
To enable multiple selection in a list box, you must set the Min
and Max
properties so that Max - Min > 1
. This requires you to change the default Min
and Max
values of 0
and 1
to meet these conditions. Use the Property Inspector to set these properties on the list box.
How Users Select Multiple Items
List box multiple selection follows the standard for most systems:
Users must use one of these techniques to select the two variables required to create the plot.
Returning Variable Names for the Plotting Functions
The get_var_names
subroutine returns the two variable names that are selected when the user clicks on one of the three plotting buttons. The function
String
property.
Value
property.
get_var_names
displays an error dialog explaining that the user must select two variables.
Here is the code for get_var_names
:
function [var1,var2] = get_var_names(handles) list_entries = get(handles.listbox1,'String'); index_selected = get(handles.listbox1,'Value'); if length(index_selected) ~= 2 errordlg('You must select two variables',... 'Incorrect Selection','modal') else var1 = list_entries{index_selected(1)}; var2 = list_entries{index_selected(2)}; end
Callbacks for the Plotting Buttons
The callbacks for the plotting buttons call get_var_names
to get the names of the variables to plot and then call evalin
to execute the plot commands in the base workspace.
For example, here is the callback for the plot
function:
function plot_button_Callback(hObject, eventdata, handles) [x,y] = get_var_names(handles); evalin('base',['plot(' x ',' y ')'])
The command to evaluate is created by concatenating the strings and variables that result in the command:
Reading Workspace Variables | A GUI to Set Simulink Model Parameters |
© 1994-2005 The MathWorks, Inc.