How to change size of uitable?
128 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I have calculated a few values that I want to display in a table. Since I couldn't find any other tables for matlab I am now using uitable. The problem is that I have about 8 columns and only 2 rows. When the table is displayed it only shows me the first 3 columns and then I can scroll right to see my other values. Is there a way to make the displayed part of the table larger? I would like to see ALL my values right away!
Thanks alot!!
0 个评论
采纳的回答
Orion
2014-10-6
Hi,
you can resize the columns of your uitable.
once you have filled the table with your data, you can use the ColumnWidth parameter
something like :
figure;
data = rand(2,8);
u = uitable('Position',[20 20 500 70],'data',data)
pause(2)
set(u,'ColumnWidth',{50})
you can mix the use of the position and ColumnWidth parameters to get the result you prefer.
1 个评论
Adam
2014-10-6
uitable certainly isn't friendly to parameterise, especially if you have row headers which are not resizable without hacking around in the underlying java, but if you just have columns and rows with no row headers then this works. You have to mess about a little if you want the whole table to be displayed without scrollbars and without lots of extra space around it, but following Orion's advice will work if you do the maths on column width * number of columns and then add a couple of pixels (to ensure no scrollbars).
更多回答(1 个)
Warren Hamilton
2017-3-23
编辑:Warren Hamilton
2017-3-23
This may be a couple of years old now, but I was messing around with this earlier today. Another option is to resize the actual figure window size/position to neatly contain the uitable.
It's a little bit of a hack in the sense that this code uses hardcoded constants to allow me to set to 'outerposition' with enough space for the window boundaries etc, but it does work. There's probably a more sophisticated property to set, but I got this code working and stopped searching...
It works by
1) get the actual size of the table and set the size of the uitable object to be that size.
2) get the figure size, and modify so that it is big enough to contain the uitable data.
h = figure;
data = rand(2,8);
u = uitable('Position',[20 20 500 70],'data',data);
table_extent = get(u,'Extent');
set(u,'Position',[1 1 table_extent(3) table_extent(4)])
figure_size = get(h,'outerposition');
desired_fig_size = [figure_size(1) figure_size(2) table_extent(3)+15 table_extent(4)+65];
set(h,'outerposition', desired_fig_size);
I was doing this becauses I wanted to print the table to png so that I had something quick/dirty to insert into a draft document without mucking about with exporting to excel and importing that etc etc.. For that purpose, printing to file works, but only really if you make sure that you are printing in high resolution - using the default 'saveas' means that that quality is unusable. (again, there's ways around this using saveas, but this one works for me.)
print('-dpng', filename, '-r0'); %-r0 prints at screen resolution
1 个评论
Mubassira Syed
2024-6-4
Dear Warren Hamilton, thank you for this little hack. I had been looking around for similar thing. It helped me as well to save the table in figure format.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!