[uitable] Insert a table as a subplot
조회 수: 24 (최근 30일)
이전 댓글 표시
I am trying to insert an 8x8 table next to an existing plot. Although both of them appear in the same figure(4), the table cannot be moved or edited, therefore I cannot illustrate the results as I want to.
The code I use is provided below:
f=figure(4)
% create the data
d = od_table;
% Create the column and row names in cell arrays
cnames = {'1','2','3','4','5','6','7','8'};
rnames = {'1','2','3','4','5','6','7','8'};
% Create the uitable
t = uitable(f,'Data',d,...
'ColumnName',cnames,...
'RowName',rnames,...
'ColumnWidth',{30})
The ideal solution for me would the table to be able to be moved around the figure with fixed size, titles etc. As a 'movable legend'.
댓글 수: 0
채택된 답변
Joseph Cheng
2015년 4월 28일
I'm not entirely sure what you are describing as the ideal solution. Are you asking for a click and drag ability to dynamically move and resize items? I can't think of something right off the bat for how to accomplish that but if you want to move and resize the uitable you can do something like this
f=figure(4)
% create the data
% Create the column and row names in cell arrays
cnames = {'1','2','3','4','5','6','7','8'};
rnames = {'1','2','3','4','5','6','7','8'};
% Create the uitable
t = uitable(f,'Data',rand(8),...
'ColumnName',cnames,...
'RowName',rnames,...
'ColumnWidth',{30})
subplot(2,1,1),plot(3)
pos = get(subplot(2,1,2),'position');
delete(subplot(2,1,2))
set(t,'units','normalized')
set(t,'position',pos)
Where i get and set the uitable to fit inside subplot(2,1,2) position.
댓글 수: 2
Joseph Cheng
2015년 4월 28일
well not the cleanest way but
f=figure(4)
% create the data
% Create the column and row names in cell arrays
cnames = {'1','2','3','4','5','6','7','8'};
rnames = {'1','2','3','4','5','6','7','8'};
% Create the uitable
t = uitable(f,'Data',rand(8),...
'ColumnName',cnames,...
'RowName',rnames,...
'ColumnWidth',{30})
subplot(2,1,1),plot(3)
pos = get(subplot(2,1,2),'position');
title('table')
xlabel('xlabel')
ylabel('ylabel')
set(subplot(2,1,2),'yTick',[])
set(subplot(2,1,2),'xTick',[])
set(t,'units','normalized')
set(t,'position',pos)
set(t,'ColumnName',{'a','b','c','d','e','f','g','h'})
set(t,'RowName',{'aa','bb','cc','dd','ee','ff','gg','hh'})
추가 답변 (1개)
Adam
2015년 4월 28일
There is a ColumnEditable property that is set to be off for all columns by default. You need to set it to a logical vector with an element per column to get editable columns.
In terms of moving it around I'm not really sure what you mean. In the 'arrow' mode on a figure ( 'Edit plot' as the tooltip says ) you can drag a table around just like you can other components if you select it.
댓글 수: 4
Adam
2015년 4월 28일
column are row names are already a part of uitable. A title can be given just by a text control if you wish.
Being able to drag a UI component around without clicking on the relevant toolbar button in the figure to put you in that mode is not possible as far as I am aware though.
Obviously you could program it yourself using the Mouse move callback and ButtonDown callback etc, but that is not at all trivial.
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!