Hi. I want to programatically add a uitable to a subplot position (without using guide). Whilst I have been able to do this, Im not able to fill the subplot region. Is it possible to do this (at least in the horizontal dimension)
This is my code:
% create the data
% Create the column and row names in cell arrays
cnames = {'Z','FMc','FMc','AvgI'};
rnames = {'1','2','3','4','5','6','7','8'};
% Create the uitable
t = uitable(f1,'Data',data,...
'ColumnName',cnames,...
'RowName',rnames,...
'ColumnWidth',{50});
subplot(1,2,2),plot(3)
pos = get(subplot(1,2,2),'position');
delete(subplot(1,2,2))
set(t,'units','normalized')
set(t,'position',pos)
I was wondering if the ColumnWidth variable could somehow be calculated from the subplot width?

 채택된 답변

Jan
Jan 2016년 12월 26일

2 개 추천

% Auto-resize:
jScroll = findjobj(t);
jTable = jScroll.getViewport.getView;
jTable.setAutoResizeMode(jTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
drawnow;

댓글 수: 4

Jason
Jason 2017년 1월 3일
Thanks, thats perfect!
Spencer G
Spencer G 2017년 8월 23일
Thanks Jan! Do you know how to auto-resize the rows too? I tried "jTable.AUTO_RESIZE_SUBSEQUENT_ROWS" but it doesn't seem to exist.
Jan
Jan 2017년 8월 23일
@Spencer G: You are right, there is not auto-resizing of rows. I've found some links about auto-resizing of tables vertically:
But I do not have time to implement this in Matlab currently.
Emily Pitts
Emily Pitts 2022년 7월 28일
I've been looking for a solution to this for days, and your solution worked perfectly in MATLAB 2022a. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

M E
M E 2018년 6월 29일

0 개 추천

This one might also be useful: How do I place a uitable in a subplot

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

질문:

2016년 12월 23일

댓글:

2022년 7월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by