MATLAB: How to get the cells in a table created in GUIDE to fill the full size of the table

columnguideMATLABuitablewidth

When I create a table in GUIDE, the cells do not fill the full size of the table resulting in whitespace around the group of table cells. How can I get the cells to fill the full size of the table?

Best Answer

There are two possible approaches to achieve this result:
Approach 1 - Change the table's column widths so they match the width of the table. You can do this manually in GUIDE by right-clicking on the table, selecting Property Inspector, and modifying the ColumnWidth property. Or you can do this programmatically in the OpeningFcn function, as shown:
% Change the tables column widths to match the width of the table
table = handles.uitable1;
table.Units = 'pixels';
width = table.Position(3)-31; % subtracting by 31 to account for row header
ncol = size(table.Data, 2);
table.ColumnWidth = num2cell(ones(1,ncol)*width/ncol);
Approach 2 - Change the table's width and height so they match the width and height of the collection of cells in the table. You can do this programmatically in the OpeningFcn function, as shown:
% Change the tables width and height to match the width and height of cells in the table
table = handles.uitable1;
table.Position(3) = table.Extent(3);
table.Position(4) = table.Extent(4);