MATLAB GUI developers often want to have a mini-spreadsheet in their GUI. This can be done with a new widget added to the set of controls available in GUIDE. Now with UITABLE you can add that capability. This video shows how to add a table for display, then makes it editable and adds a callback such that MATLAB code is run whenever a cell in the table is edited. The data is not linked to the variables in the workspace, so this callback shows you how to pull data out of the table whenever it is updated.
Doug, nice post. One thing, though: it occurs to me that you haven’t shown us how to use/share the value of the variable DATA (from the data in the table) outside of the workspace of the cellEditCallback workspace. There are several ways to do it–addressing the ways, and their relative merits, would make a nice follow-up blog!
UITable was undocumented, but available, for some releases in the past.
Some features like this are available, but undocumented, for various reasons. Sometimes they are there so that we can use them in making tools for MATLAB. These features are undocumented because we need the flexibility to change the interface for a while. If you find undocumented features, you need to be aware that the interface can change or be removed in future releases.
As far as access is concerned, the undocumented uitable of old provided cut and paste options from a uicontextmenu but the new version does not. Is that something that will be addressed in future releases?
I have a gui with a uitable that works well when you hit enter after each cell edit, but when you hit tab after editing a cell’s contents, the CellEditCallback is not executed. Is there a fix for this?
My question follows the previous post here. I am trying to edit the cells of a table. It works well if I hit tab after entering data. However, if I choose the contents of a cell by mouse-click-and-drag, and edit it, unless I click in another cell, the CellEditCallback is not called. I tend to edit the last cell, and then directly press a button that processes the data. So, I end up missing the data on the last cell I edit. How can I rectify this?
By the way, I am sincerely grateful for the most educative and helpful posts. I even considered developing GUI, solely due to your videos.
Hi, I have Matlab 7.5.0 (R2007b) and I need to create a table on an interface, but in the GUI doesn’t exist a botton to create it, do I have to install something to obtain that botton in my GUI
I am investigating a way of loading the uitable with data from two variables. One is a 10×12 double however the second is a 12×13 cell. Is this achievable in any way?
You are going to have to decide how you want these odd shaped pieces to fit together. I recommend putting them all into one big cell, then setting that to the data as normal.
Thanks for your advice, i have merged the data into a cell however when i select the cell in Property Inspector – Data, it will not display the cell data. If i choose a double array i have in the Workspace it displays fine!
Do i need to convert the data within the cell to allow uitable to accept it?
Please, i have never used tables before in matlab and i am using matlab R2007b. Il like to know how to create a table. This is how its supposed to work—I have 2 GUI windows, one for collecting user data like name , gender, address etc and the secon GUI window is the one that should contain the table. I will like a case whereby a user inputs his/her personal details in the first GUI and on pressing “update button” from that first GUI window, it gets added to the table of the second GUI. As different other users key in their personal details and clicks on “update button”, that table continues to be populated and updated
Uitables seem like a convenient way to make a customized property inspector for when there are lots of adjustable parameters in the application. This works well when the parameters all have the same format, otherwise to make use of the column formatting & input features we can only make a “transposed” version (side scrolling, not so pretty).
Having row formatting as an option would be nice. Are there any plans for this in future versions – or is there a better way to go about this?
I have been using GUIDE to build a table that will need 1 column and some number of rows. So, I create a table in GUIDE, which by default has 2 columns and 4 rows, but when I open the Table Property Editor and try to delete the second column (bringing the total number of columns to 1), hitting “Apply” does not delete the column in the GUI, but instead causes the column to reappear in the Table Property Editor. This only happens when the table has two columns, i.e. if I have three columns, I can delete one of them. My application only needs one column and this will be a professional tool, so I really don’t want to have a blank column just hanging there. Is this a known problem? Any workarounds?
Note also that the same issue arises for rows. If I delete some number of rows so that the total number of rows is less than 4, then hitting “Apply” reverts the setup to 4 rows.
Nevermind, I’ve figured it out. Looking through the background (GUIDE-exported) code, I found that the number of columns looks to be set by the column names and data. So, in my case, the code looks like:
Note that I’ve cut out some of the unimportant code for readability. So, returning to the m-file that goes with the GUIDE fig file, I need only put the following line in the uitable’s CreateFcn,
Looks like you figured it out. The enhancement to allow this must have been implemented while I was not looking! I have deleted the earlier posts to clean this thread up since you figured it out!
I’m trying to build a GUI with a 6 x 8 matrix that outputs to the workspace. I have managed to build a nice table with the inital values, column- and rowheaders that I wanted to have displayed using your tutorial. I also manage to get output to the commandwindow via the type of code used in the last part of your tutorial. However, I don’t seem to get it to output the matrix from the GUI to the workspace. All help would be appreciated.
I have created a uitable using the GUIDE, and modifying the properties like ‘RowName’ programmatically(because it cant be fixed). If I give more than 4 rownames(say 6), the 6 rows are visible with the appropriate rownames. But the values of the 5th row onwards are not returned to the workspace.
Please provide a solution for the same.
Thanks for replied. But I still need a little help. How do I make the command for load the data and the command to place the data into the table ? In fact, if it possible, could you please provide me the code for this purpose ?
This video shows how to set the value of data in a UITABLE. XLSREAD will get the data into MATLAB. Look in the Excel section of this blog to find videos on how to read the data in from Excel in MATLAB.
My question,
why is it if i try get the data from the table, it appears the quote sign (”) in each element even if i have set the format to be numeric in column option.. str2num doesnt work too.. Maybe filling the table with ‘workspace data’ will do the trick, but i want the table to be empty before user edit/input the table.
First, your videos are always very useful! Keep up the good work!
Second, the uitable doesn’t allow the user to copy and paste data into the uitable cells from Excel. I would like to have this functionality, but am unsure how to accomplish it.
I am aware that I could prompt the user to select an Excel file and read the data that way, but different users may not have to same Excel sheet formating. A simple copy and paste utility would work wonderfully.
I was, however, able to come up with a suitable solution.
I added a button to go along with the table, appropriately labeled “Paste”. I added the following code to the button callback:
So are these tables only numeric, or can we use a mixed type cell array to populate them?
Also I am currently using 7.5 and see that these tables are available but undocumented. It seems like in this version the ‘data’ is a java object.
Doug, nice post. One thing, though: it occurs to me that you haven’t shown us how to use/share the value of the variable DATA (from the data in the table) outside of the workspace of the cellEditCallback workspace. There are several ways to do it–addressing the ways, and their relative merits, would make a nice follow-up blog!
Brett, I agree. Given that the uitable is a new addition to MATLAB it would be great to see more discussion about various access methods.
Harold,
UITable was undocumented, but available, for some releases in the past.
Some features like this are available, but undocumented, for various reasons. Sometimes they are there so that we can use them in making tools for MATLAB. These features are undocumented because we need the flexibility to change the interface for a while. If you find undocumented features, you need to be aware that the interface can change or be removed in future releases.
-Doug
As far as access is concerned, the undocumented uitable of old provided cut and paste options from a uicontextmenu but the new version does not. Is that something that will be addressed in future releases?
Malcolm,
This suggestion has been entered into our internal enhancement request database. Thanks for the suggestion.
Doug
Hello Doug,
I have a gui with a uitable that works well when you hit enter after each cell edit, but when you hit tab after editing a cell’s contents, the CellEditCallback is not executed. Is there a fix for this?
Thanks,
Austin DeHart
Austin,
This is a known issue. I see that it has been fixed in the next release.
Doug
Hey Doug,
My question follows the previous post here. I am trying to edit the cells of a table. It works well if I hit tab after entering data. However, if I choose the contents of a cell by mouse-click-and-drag, and edit it, unless I click in another cell, the CellEditCallback is not called. I tend to edit the last cell, and then directly press a button that processes the data. So, I end up missing the data on the last cell I edit. How can I rectify this?
By the way, I am sincerely grateful for the most educative and helpful posts. I even considered developing GUI, solely due to your videos.
Thank you very much,
Keerthi
Keerthi,
Our developers are aware of that behavior. A change in behavior is likely in an upcoming release.
Doug
Hi, I have Matlab 7.5.0 (R2007b) and I need to create a table on an interface, but in the GUI doesn’t exist a botton to create it, do I have to install something to obtain that botton in my GUI
Thanks.
Hector,
This was a new feature of 2008a. You will need to upgrade to get the functionality.
Doug
Doug,
I am investigating a way of loading the uitable with data from two variables. One is a 10×12 double however the second is a 12×13 cell. Is this achievable in any way?
Many thanks Doug,
Waggy
Waggy,
You are going to have to decide how you want these odd shaped pieces to fit together. I recommend putting them all into one big cell, then setting that to the data as normal.
Doug
Doug,
Thanks for your advice, i have merged the data into a cell however when i select the cell in Property Inspector – Data, it will not display the cell data. If i choose a double array i have in the Workspace it displays fine!
Do i need to convert the data within the cell to allow uitable to accept it?
Thanks Doug,
Waggy
Waggy,
Here is a very simple example:
t = uitable(‘Data’,{1 2 3; ’1′ ’2′ ’3′})
This is a cell array with strings and numerics. It works fine.
Doug
Hello,
Please, i have never used tables before in matlab and i am using matlab R2007b. Il like to know how to create a table. This is how its supposed to work—I have 2 GUI windows, one for collecting user data like name , gender, address etc and the secon GUI window is the one that should contain the table. I will like a case whereby a user inputs his/her personal details in the first GUI and on pressing “update button” from that first GUI window, it gets added to the table of the second GUI. As different other users key in their personal details and clicks on “update button”, that table continues to be populated and updated
Rossonera,
http://blinkdagger.com/matlab/matlab-gui-tutorial-uitable-part-1-how-to-display-data
This might help you!
Doug
Doug,
Thanks for the very helpful videos!
Uitables seem like a convenient way to make a customized property inspector for when there are lots of adjustable parameters in the application. This works well when the parameters all have the same format, otherwise to make use of the column formatting & input features we can only make a “transposed” version (side scrolling, not so pretty).
Having row formatting as an option would be nice. Are there any plans for this in future versions – or is there a better way to go about this?
Doug,
I have been using GUIDE to build a table that will need 1 column and some number of rows. So, I create a table in GUIDE, which by default has 2 columns and 4 rows, but when I open the Table Property Editor and try to delete the second column (bringing the total number of columns to 1), hitting “Apply” does not delete the column in the GUI, but instead causes the column to reappear in the Table Property Editor. This only happens when the table has two columns, i.e. if I have three columns, I can delete one of them. My application only needs one column and this will be a professional tool, so I really don’t want to have a blank column just hanging there. Is this a known problem? Any workarounds?
Note also that the same issue arises for rows. If I delete some number of rows so that the total number of rows is less than 4, then hitting “Apply” reverts the setup to 4 rows.
Thanks.
-Taylor
Nevermind, I’ve figured it out. Looking through the background (GUIDE-exported) code, I found that the number of columns looks to be set by the column names and data. So, in my case, the code looks like:
h11 = uitable(... 'ColumnName',{ blanks(0); blanks(0)},... 'Data',{blanks(0) blanks(0);blanks(0) blanks(0);blanks(0) blanks(0);blanks(0) blanks(0)});Note that I’ve cut out some of the unimportant code for readability. So, returning to the m-file that goes with the GUIDE fig file, I need only put the following line in the uitable’s CreateFcn,
set(hObject,'ColumnName',blanks(0),'Data',{blanks(0);blanks(0);blanks(0)});And voila, the table is initialized to be empty with 3 rows and 1 column.
@Taylor,
Looks like you figured it out. The enhancement to allow this must have been implemented while I was not looking! I have deleted the earlier posts to clean this thread up since you figured it out!
Doug
Dear Doug,
I’m trying to build a GUI with a 6 x 8 matrix that outputs to the workspace. I have managed to build a nice table with the inital values, column- and rowheaders that I wanted to have displayed using your tutorial. I also manage to get output to the commandwindow via the type of code used in the last part of your tutorial. However, I don’t seem to get it to output the matrix from the GUI to the workspace. All help would be appreciated.
Vidar
@Vidar,
I think this would be a good video to watch.
http://blogs.mathworks.com/videos/2010/02/12/advanced-getting-an-output-from-a-guide-gui/
Doug
Hi Doug,
Nice video.
Would it be possible to copy data from an excel sheet and paste these data in a table (doing ctrl+v or something like that)?
Thanks,
Juan
I have created a uitable using the GUIDE, and modifying the properties like ‘RowName’ programmatically(because it cant be fixed). If I give more than 4 rownames(say 6), the 6 rows are visible with the appropriate rownames. But the values of the 5th row onwards are not returned to the workspace.
Please provide a solution for the same.
Thanks,
Rama
@Rama,
Please send the shortest reproduction code that shows the behavior and we will take a look at it.
doug
I got the answer for my problem from the following discussion.
http://www.mathworks.de/matlabcentral/newsreader/view_thread/248886
Thanks for offering the help.
-
Rama
Hi Doug
is there any way to import data from an excel file directly to a Table in GUI ? if so, can you tell me how do I do it please, I need some help.
Thanks for the help.
@Ricardo,
It will take two commands, one to load it in, one to place it in the table. Once put into a little function, it can seem like a single command though.
Doug
Hi Doug
Thanks for replied. But I still need a little help. How do I make the command for load the data and the command to place the data into the table ? In fact, if it possible, could you please provide me the code for this purpose ?
ah, the table in GUI is only for consulting not to editing.
@Ricardo,
This video shows how to set the value of data in a UITABLE. XLSREAD will get the data into MATLAB. Look in the Excel section of this blog to find videos on how to read the data in from Excel in MATLAB.
Doug
Hello Doug.
Im new to Matlab, using 2009a.
My question,
why is it if i try get the data from the table, it appears the quote sign (”) in each element even if i have set the format to be numeric in column option.. str2num doesnt work too.. Maybe filling the table with ‘workspace data’ will do the trick, but i want the table to be empty before user edit/input the table.
thanks.
@Pardosi,
Please send reproduction steps to me via e-mail.
Doug
thank you so much doug..it works.
then I want to display the graphic from network in nntool of matlab into gui again.
best regards,
Chia
Hi Doug,
First, your videos are always very useful! Keep up the good work!
Second, the uitable doesn’t allow the user to copy and paste data into the uitable cells from Excel. I would like to have this functionality, but am unsure how to accomplish it.
I am aware that I could prompt the user to select an Excel file and read the data that way, but different users may not have to same Excel sheet formating. A simple copy and paste utility would work wonderfully.
Any suggestions?
Thanks!
@Matthew,
I have put in a request for that functionality. Let us hope that the priority is high enough for it to happen soon!
Doug
Doug,
Thank you for your prompt response!
I was, however, able to come up with a suitable solution.
I added a button to go along with the table, appropriately labeled “Paste”. I added the following code to the button callback:
raw_data = importdata('-pastespecial'); set(handles.input_table,'Data',raw_data)Of course, I added code between those two lines to make sure the user is entering numeric data and in the correct size dimensions! :-P
Thanks!