{"id":215,"date":"2008-06-02T07:20:28","date_gmt":"2008-06-02T12:20:28","guid":{"rendered":"https:\/\/blogs.mathworks.com\/desktop\/2008\/06\/02\/tables-in-matlab-with-uitable\/"},"modified":"2016-08-16T14:24:09","modified_gmt":"2016-08-16T18:24:09","slug":"tables-in-matlab-with-uitable","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2008\/06\/02\/tables-in-matlab-with-uitable\/","title":{"rendered":"Tables in MATLAB with uitable"},"content":{"rendered":"<p><i><br \/>\nI&#8217;d like to welcome guest blogger Denis Hanson from the GUI Building team. Denis will occasionally be blogging here on the <a href=\"https:\/\/blogs.mathworks.com\/community\/\">Inside the MATLAB Desktop<\/a> blog.<br \/>\n<\/i><\/p>\n<p>In R2008a, we added the <tt>uitable<\/tt> control, as well as support for this new control in Guide. The <tt>uitable<\/tt> component enables the display of data in a two dimensional table. You can use the <a href=\"https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/index.html?\/access\/helpdesk\/help\/techdoc\/creating_plots\/f9-47085.html#f9-43456\">Property Inspector<\/a> or the new <a href=\"https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/index.html?\/access\/helpdesk\/help\/techdoc\/creating_guis\/f8-998368.html#brhj849\">Table Property Editor<\/a> to get and set <tt>uitable<\/tt> object property values (to open the Property Inspector type <a href=\"https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/index.html?\/access\/helpdesk\/help\/techdoc\/ref\/inspect.html\"><tt>inspect<\/tt><\/a> at the command prompt; to open the Table Property Editor, right-click your <tt>uitable<\/tt> in Guide and select <i>Table Property Editor&#8230;<\/i>).<\/p>\n<p>The Table Property Editor makes it easy to define the layout of a table inside Guide. The Property Inspector could be used to achieve the same results, though it&#8217;s not targeted to <tt>uitable<\/tt>. Lets look at using the Table Property Editor to setup a <tt>uitable<\/tt>.<\/p>\n<p>Table properties fall into four natural categories, which are presented on separate panels. Here&#8217;s a listing of each of the Table Property Editor&#8217;s panels, and what you can do on each:<\/p>\n<ul>\n<li><b>Columns<\/b> \u2013 set column names, format, size, and editability<\/li>\n<li><b>Rows<\/b> \u2013 set row names<\/li>\n<li><b>Data<\/b> \u2013 select data to display in the table<\/li>\n<li><b>Colors<\/b> \u2013 set colors and control row striping<\/li>\n<\/ul>\n<p>Notice also that at the top of each panel is a help section. The text in the panel will change to reflect the option that is currently selected on the property panel.<\/p>\n<p>Let&#8217;s look at each of the panels in detail.<\/p>\n<p><b>Columns Panel<\/b><\/p>\n<div align=\"center\"><a  href=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/table_property_editor_columns.jpg\"><img decoding=\"async\"  border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/table_property_editor_columns_small.jpg\"><\/a><\/div>\n<p>The Column Headers section of this panel lets you control how and if column headers are displayed. The Column Definitions section of this panel lets you tweak properties for each column and also allows the insertion, removal and rearranging of columns.<\/p>\n<p>The Format column in the Column Definitions table specifies how the data should be formated for viewing. Here are each of the options and what they do:<\/p>\n<ul>\n<li><b>Let MATLAB Choose<\/b> &#8211; MATLAB chooses a format that most closely matches the underlying column data. For example, if the data in the column is doubles, the <i>Numeric<\/i> display option will be used.<\/li>\n<li><b>Choice List<\/b> &#8211; allows you to enter a series of series of values that will be displayed in a popupmenu.  This option is especially useful if the column is editable and you want to restrict the values that they user can enter.\n<div align=\"center\"><a  href=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/choice_list_editor.jpg\"><img decoding=\"async\"  border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/choice_list_editor_small.jpg\"><\/a><\/div>\n<\/li>\n<li><b>Format<\/b> &#8211; lets you choose from a pre-defined list of formats for displaying numeric data.  The options are the same as those found in the <a href=\"https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/index.html?\/access\/helpdesk\/help\/techdoc\/ref\/format.html\"><tt>format<\/tt><\/a> function.\n<div align=\"center\"><a  href=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/custom_format_editor.jpg\"><img decoding=\"async\"  border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/custom_format_editor_small.jpg\"><\/a><\/div>\n<\/li>\n<\/ul>\n<p><b>Rows Panel<\/b><\/p>\n<div align=\"center\"><a  href=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/table_property_editor_rows.jpg\"><img decoding=\"async\"  border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/table_property_editor_rows_small.jpg\"><\/a><\/div>\n<p>The Rows panel lets you define how row headers are displayed. Row headers are shown in an additional column at the left edge of the table. They do not contain table data values. If shown, they typically display the row number, but you can enter a custom name for each row.<\/p>\n<p><b>Data Panel<\/b><\/p>\n<div align=\"center\"><a  href=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/table_property_editor_data.jpg\"><img decoding=\"async\"  border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/table_property_editor_data_small.jpg\"><\/a><\/div>\n<p>The Data panel lets you populate the table with data from workspace variables. A table row will be created for each row in your data set and a table column will be created for each column in your data set. Once you have saved the data into the table, the table contains a copy of the data. The table data is not linked to the workspace variable so further modifications to the workspace variable will not be reflected in the table.<\/p>\n<p>The values you set here are used to populate the table when your figure is displayed.  This is useful if you have canned data that does not change. If your data is not fixed, you should select the <i>Do not set data value and leave the table empty<\/i> option. You will then need to load table data programmatically.<\/p>\n<p><b>Colors Panel<\/b><\/p>\n<div align=\"center\"><a  href=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/table_property_editor_colors.jpg\"><img decoding=\"async\"  border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/denis_hanson_tables_in_matlab_with_uitable\/table_property_editor_colors_small.jpg\"><\/a><\/div>\n<p>The Colors panel lets you define the background, foreground, and row-striping colors used to paint the cells in the table. When row-striping is on the table paints odd and even rows using different background colors. The striping effect makes it easier for a user to scan the data in a table row, especially if there are many rows of data.<\/p>\n<p>This was a world-wind tour of the new <tt>uitable<\/tt> control &#8211; in a future post, we&#8217;ll show you how to use the new control in a real application.<\/p>\n<p>Let us know what you think about <tt>uitable<\/tt>!<\/p>\n<p><i><br \/>\n-by Denis Hanson, The MathWorks<br \/>\n<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\nI&#8217;d like to welcome guest blogger Denis Hanson from the GUI Building team. Denis will occasionally be blogging here on the Inside the MATLAB Desktop blog.<\/p>\n<p>In R2008a, we added the uitable&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2008\/06\/02\/tables-in-matlab-with-uitable\/\">read more >><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/215"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":4009,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/215\/revisions\/4009"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}