How to change size of uitable?
조회 수: 127 (최근 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!