MATLAB GUI Tutorial - UITABLE Part 1, How to Display Data
27 May 2009 Quan Quach 7 comments 5,788 views
With the release of MATLAB 2008b, you are now able to add tables to a GUI. In the past, there was no easy way to display your data in tabular form. With the UITABLE component, displaying your data in tabular form is easy, and most importantly, looks great!

Contents
- Adding a Table to Your GUI using GUIDE
- Displaying Data on the Table
- Adding Column and Row Labels
- Modifying your Table through the m-file
- Next Time
- Links and Downloads
Adding a Table to Your GUI using GUIDE
Within the GUIDE framework, you can add a table to your GUI using the following icon from the toolbar:
.
Here’s what the GUI will look like within GUIDE:

Displaying Data on the Table
We are going to populate the UITABLE component with data by pushing the “Populate Table” button. Thus, we’re going to need to add some code to the pushbutton’s callback. In the populate_pushbutton callback, we use the following code:
% --- Executes on button press in populate_pushbutton. function populate_pushbutton_Callback(hObject, eventdata, handles) % hObject handle to populate_pushbutton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %first, create a data matrix that has 5 columns, 4 rows myData = rand(5,4); %now populate the table with the above values set(handles.uitable1,'data',myData );
Now, let’s run the GUI and push the button!

A neat feature is that the table is smart enough to fill out the table according to the size of the data matrix that you feed it. So if I had done the following instead:
myData = rand(100,100);
The table would incorporate the use of scroll bars, as shown below.

Adding Column and Row Labels
A good way to spruce up your table is to add row and column labels. This helps differentiate your data and makes it easy to identify. Within the GUIDE framework, we can modify the labels by first bringing up the Property Inspector for the UITABLE. This can be done by double clicking the UITABLE component.

Now, if you click on any of the fields in the above picture, it will bring up the Table Property Editor. This is where you can add Row and Column labels. For example:

Make sure you click on the “Rows”, and that you select the “Show names entered below as the row headers” option. Finally, you just need to modify the names. Similarly, you can do the same for the columns.

Once you’re done with that. you should see the following:

And once you run your GUI, you can see the final result. A well labeled table that displays your data beautifully!

Modifying your Table through the m-file
Sometimes it’s easier to work from within the m-file framework, rather than the GUIDE framework. We could have done exactly what we did above programmatically through the m-file. In the opening function we could have done the following:
%store the row headers into a cell array rowHeaders = {'Blink','Dagger','Loves','MATLAB','!!!!!!'}; %set the row labels set(handles.uitable1,'RowName',rowHeaders); %do the same for the column headers columnHeaders = {'Quan','Daniel','Rob','Zane'}; set(handles.uitable1,'ColumnName',columnHeaders);
In this example, we assumed that we knew the dimensions of our table. If you don’t know the size of your table beforehand, then it can be difficult to apply data labels that are meaningful. By working through the m-file, you obtain more flexibility since you won’t have to go back and modify the .fig file every time you want to make a change. And if you are going to apply dynamic labeling, then working from the m-file is going to be much easier.
Next Time
Next time, we’re going to talk about how to work with manipulating the data within the table.
Links and Downloads
Download Source Files
The MathWorks Documentation for UITABLE
Cool Things You can do with UITABLE
Doug’s Video on UITABLE
7 Responses to “MATLAB GUI Tutorial - UITABLE Part 1, How to Display Data”
Leave a Reply
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>


Hi Quan
I was wondering how one could display a result in one selective cell of a GUI table?.
i will ask a question i hope there is anyone will answer
i wanna when i select (or click) one data from table, it must select all the rows data (for example if i select (1,1) from that matrix table it will be selected (1,1) (1,2) (1,3) (1,4) ) thanks for helping from now.
I have the same question as Shobana, How can I control one cell of table? For example, I want to fill table A1 with number”10″, fill table A2 with string “good”.
Thx in advance
Hi
I was wondering if anyone knew how to use a GUI to enable a block in Simulink or where I could find this info? I have created the layout for a GUI in GUIDE with a pop-up menu to select between different blocks in a Simulink simulation. I just want to know how to inferface between the GUI and the Simulink model so that when an option is selected from the pop-up menu the corresponding block in the simulatiuon will be enabled.
I was wondering if anyone knows how to do this - what if you want to display data from an outside file (say, “mydata.mat”) in your table instead of randomly generated numbers? What would you change in order to do that? Thanks.
Hi?
I made one interface in Matlab. that is running now. But I wanna to rearrange that GUI. So that I want to know “How to apply TAB strip in Marlab? ”
Is there anyone help me?
Hi QUAN !
Is there any way to creat a matrix side(n*n) and a vector (n) in GUI but don’t display the data in the table like you’ve done ???
Thanks from Campodia hehehehe