[uitable] Insert a table as a subplot

23 views (last 30 days)
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'.

Accepted Answer

Joseph Cheng
Joseph Cheng on 28 Apr 2015
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 Comments
Emmanouil Barmpounakis
Emmanouil Barmpounakis on 28 Apr 2015
Edited: Emmanouil Barmpounakis on 28 Apr 2015
Yes, Joseph I would like a click and drag ability as you describe in your reply.
If this is not possible, I would be OK if I could give a title to this table and also a name to columns and rows (like the title,xlabel and ylabel properties for a figure).
Thank you for your time.
Joseph Cheng
Joseph Cheng on 28 Apr 2015
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'})

Sign in to comment.

More Answers (1)

Adam
Adam on 28 Apr 2015
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 Comments
Emmanouil Barmpounakis
Emmanouil Barmpounakis on 28 Apr 2015
Edited: Emmanouil Barmpounakis on 28 Apr 2015
I am sorry but I can not understand what you suggest.
As I write in a comment below, if moving the table is not possible, I would be OK if I could give a title to this table and also a name to columns and rows (like the title,xlabel and ylabel properties for a figure).
Any ideas on that? Thank you for your time.
Adam
Adam on 28 Apr 2015
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.

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!