Documentation Center

  • Trial Software
  • Product Updates


Create 2-D graphic table GUI component


uitable('PropertyName1', value1,'PropertyName2',value2,...)
handle = uitable(...)


uitable creates an empty uitable object in the current figure window, using default property values. If no figure exists, a new figure window opens.

uitable('PropertyName1', value1,'PropertyName2',value2,...) creates a uitable object with specified property values. Properties that you do not specify assume the default property values. See the Uitable Properties reference page for information about the available properties.

uitable(parent,...) creates a uitable object as a child of the specified parent handle parent. The parent can be a figure or uipanel handle. If you also specify a different value for the Parent property, the value of the Parent property takes precedence.

handle = uitable(...) creates a uitable object and returns its handle.


Create a table, provide magic-square data, set column widths uniformly, and specify the uitable ColumnWidth property as a cell array:

  1. Create a table in the current figure. If no figure exists, one opens:

    t = uitable; 

  2. As the table has no content (its Data property is empty), it initially displays no rows or columns. Provide data (a magic square)


  3. Make the entire table contents visible. Set column widths to 25 pixels uniformly. Specify the ColumnWidth property of the table as a cell array.


    Cell arrays that specify ColumnWidth can contain:

    • One number (a width measured in pixels, as shown here) or the string 'auto'.

    • A cell array containing a list of pixel sizes having up to as many entries as the table has columns .

    If a list of column widths has n entries, where n is smaller than the number of columns, it sets the first n column widths only. You can substitute 'auto' for any value in the cell array to have the width of that column calculated automatically.


Create a figure and add a table to contain a 3-by-3 data matrix. The code specifies the column names, row names, parent, and position of the table:

f = figure('Position',[200 200 400 150]);
dat = rand(3); 
cnames = {'X-Data','Y-Data','Z-Data'};
rnames = {'First','Second','Third'};
t = uitable('Parent',f,'Data',dat,'ColumnName',cnames,... 
            'RowName',rnames,'Position',[20 20 360 100]);


Create a table to contain a 3-by-4 array that contains numeric, logical, and string data, as follows:

  • First column (Rate): Numeric, with three decimals (not editable)

  • Second column (Amount): Currency (not editable)

  • Third column (Available): Check box (editable)

  • Fourth column (Fixed/Adj): Pop-up menu with two choices: Fixed and Adjustable (editable)

  • Specify the RowName property as empty to remove row names from the table.

f = figure('Position',[100 100 400 150]);
dat =  {6.125, 456.3457, true,  'Fixed';...
        6.75,  510.2342, false, 'Adjustable';...   
        7,     658.2,    false, 'Fixed';};
columnname =   {'Rate', 'Amount', 'Available', 'Fixed/Adj'};
columnformat = {'numeric', 'bank', 'logical', {'Fixed' 'Adjustable'}};
columneditable =  [false false true true]; 
t = uitable('Units','normalized','Position',...
            [0.1 0.1 0.9 0.9], 'Data', dat,... 
            'ColumnName', columnname,...
            'ColumnFormat', columnformat,...
            'ColumnEditable', columneditable,...


You can add tables to GUIs you create with Table.

More About

expand all


After creating a uitable object, you can set and query its property values using the set and get functions.

If the ColumnEditable property is true for columns you edit, you can change values in a displayed table. By default, this property is false for all columns. If a noneditable column contains pop-up choices, only the current choice is visible (and not the pop-up menu control).

If you attempt to create a uitable object when running MATLAB® on a UNIX® system without a Java® virtual machine (matlab -nojvm) or without a display (matlab –nodisplay), no table generates and you receive an error.

The CellEditCallback executes after you edit a value and do any of the following:

  • Type Enter.

  • Click another table cell.

  • Click anywhere else within the table.

  • Click another control or area within the same figure window.

  • Click another window, click again on the GUI containing the table (or use Alt+Tab to switch windows), and then perform any of the above four actions.

When the CellEditCallback callback executes, uitable updates the underlying data matrix (the table Data property) to contain the value that the cell now displays.

The CellSelectionCallback executes when you select a table cell or remove one from the current selection by Ctrl+clicking it. Clicking a cell without pressing any key selects it and deselects all currently selected cells. You can define a range of table cells by Shift+clicking an unselected cell after selecting one or more cells. The callback provides event data that identifies the rows and columns of all cells in the current selection.

You cannot select table cells programmatically. Directly clicking cells is the only method of selection.

See Also

| | | | |


Was this topic helpful?