14 Examples of UIs Created Programmatically
View the Example Code
To obtain copies of the program files for this example, follow these steps:1 Set your current folder to one to which you have write access.
2 Copy the example code and display it in the Editor by issuing the following MATLAB
commands:copyfile(fullfile(docroot, 'techdoc','creating_guis',...
'examples','tableplot.m')),...
fileattrib('tableplot.m', '+w');
edit tableplot.mSet Up and Interact with the uitable
This example has one file, tableplot.m, that contains its main function plus two local
functions (uicontrol callbacks). The main tableplot function creates a figure and
populates it with uicontrols and one axes.The function hides the figure's menu bar because it is not needed.% Create a figure that will have a uitable, axes and checkboxes
figure('Position', [100, 300, 600, 460],...
'Name', 'TablePlot',... % Title figure
'NumberTitle', 'off',... % Do not show figure number
'MenuBar', 'none'); % Hide standard menu bar menusThe main tableplot function sets up the uitable immediately after loading a data
matrix into the workspace. The table's size adapts to the matrix size (matrices for
uitables must be 1-D or 2-D).% Load some tabular data (traffic counts from somewhere)
count = load('count.dat');
tablesize = size(count); % This demo data is 24-by-3% Define parameters for a uitable (col headers are fictional)
colnames = {'Oak Ave', 'Washington St', 'Center St'};
% All column contain numeric data (integers, actually)
colfmt = {'numeric', 'numeric', 'numeric'};
% Disallow editing values (but this can be changed)
coledit = [false false false];
% Set columns all the same width (must be in pixels)
colwdt = {60 60 60};