MATLAB Creating Graphical User Interfaces

(Barry) #1
Synchronized Data Presentations in a GUIDE UI

Initialize the Data Table


Although you can use the Opening Function to load data into a table, this example uses
GUIDE to put data into the Data Set table. This way, the data becomes part of the
figure after you save it. Initializing the table data causes the table to have the same
number of rows and columns as the variable that it contains:


1 Access the sunspot example data set. In the Command Window, type:


load sunspot.dat
The variable sunspot, a 288-by-2 double array, displays in the MATLAB workspace.

2 Open the Property Inspector for the data table by double-clicking the Data Set table.


3
In the Property Inspector, click the Table Editor icon to the right of the Data
property to open the Table Property Editor.


4 In the Table Property Editor, select Table from the list in the left-hand column.


5 Select the bottom radio button, Change data value to the selected workspace
variable below.


6 From the list of workspace variables in the box below the radio button, select
sunspot and click OK.


GUIDE inserts the sunspot data in the table.


Compute the Data Statistics


The Opening Function retrieves the preloaded data from the data table and calls the
local function, setStats, to compute population statistics, and then returns them. The
data_table_CellSelectionCallback performs the same action when you select
more than 10 rows of the data table. The only difference between these two calls is what
input data is provided and what column of the Data Statistics table is computed. Here
is the setStats function:


function stats = setStats(table, stats, col, peak)
% Computes basic statistics for data table.
% table The data to summarize (a population or selection)
% stats Array of statistics to update
% col Which column of the array to update
% peak Value for the peak period, computed externally


stats{1,col} = size(table,1); % Number of rows

Free download pdf