MATLAB Creating Graphical User Interfaces

(Barry) #1

14 Examples of UIs Created Programmatically


in the workspace after being copied into the table). However, the function hides the
markers immediately, only to be revealed when the user selects cells in the data table.

% Create an invisible marker plot of the data and save handles
% to the lineseries objects; use this to simulate data brushing.
hmkrs = plot(count, 'LineStyle', 'none',...
'Marker', 'o',...
'MarkerFaceColor', 'y',...
'HandleVisibility', 'off',...
'Visible', 'off');

The main function defines three check boxes to control plotting of the three columns
of data and two static text strings. You can see the code for this if you display
tableplot.m.

The Cell Selection Callback

The select_callback function for the CellSelectionCallback property, shows
and hides markers on the axes. When the user selects data values in the table, the plot
displays markers for the selected observations. This technique is called data brushing.
However, the data brushing performed by this program does not rely on MATLAB data
brushing feature.

Here is the select_callback code:

function select_callback(hObject, eventdata)
% hObject Handle to uitable1 (see GCBO)
% eventdata Currently selected table indices
% Callback to erase and replot markers, showing only those
% corresponding to user-selected cells in table.
% Repeatedly called while user drags across cells of the uitable

% hmkrs are handles to lines having markers only
set(hmkrs, 'Visible', 'off') % turn them off to begin

% Get the list of currently selected table cells
sel = eventdata.Indices; % Get selection indices (row, col)
% Noncontiguous selections are ok
selcols = unique(sel(:,2)); % Get all selected data col IDs
table = hObject.Data; % Get copy of uitable data

% Get vectors of x,y values for each column in the selection;
for idx = 1:numel(selcols)
col = selcols(idx);
Free download pdf