File Exchange Pick of the Week

May 7th, 2008

MATLAB Basics: Adding a table to a GUI

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.


Video Content

iconFiles.jpgiconPod.jpg

19 Responses to “MATLAB Basics: Adding a table to a GUI”

  1. Harold Figueroa replied on :

    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.

  2. Brett replied on :

    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!

  3. Ryan replied on :

    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.

  4. Doug replied on :

    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

  5. Malcolm Lidierth replied on :

    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?

  6. Doug replied on :

    Malcolm,

    This suggestion has been entered into our internal enhancement request database. Thanks for the suggestion.

    Doug

  7. Austin DeHart replied on :

    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

  8. Doug replied on :

    Austin,

    This is a known issue. I see that it has been fixed in the next release.

    Doug

  9. Keerthi Nagaraj replied on :

    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

  10. Doug replied on :

    Keerthi,

    Our developers are aware of that behavior. A change in behavior is likely in an upcoming release.

    Doug

  11. Hector Mejía replied on :

    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.

  12. Doug replied on :

    Hector,

    This was a new feature of 2008a. You will need to upgrade to get the functionality.

    Doug

  13. Waggy replied on :

    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

  14. Doug replied on :

    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

  15. Waggy replied on :

    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

  16. Doug replied on :

    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

  17. rossonera replied on :

    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

  18. Doug replied on :

    Rossonera,

    http://blinkdagger.com/matlab/matlab-gui-tutorial-uitable-part-1-how-to-display-data

    This might help you!

    Doug

  19. Ben replied on :

    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?

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.