writing a table into a subplot of a figure

Asked by Brad on 11 May 2012
Latest activity Commented on by Norman Koren on 1 Mar 2013

I would like to create a figure with a few subplots, at least one of these being a data table to show the statistics (mean, st. dev., st. err.) of some measurements in the plots.

How do I write a table into a figure? I have tried fprintf, disp, sprintf, all of which write into the workspace, and I have tried text which is good for writing something, but not necessarily the organization of a table. Sometimes numbers will be big and other times they will be small, so using the text command becomes complicated in laying out the table and having it fit into the subplot.

Is there a function for a table? Is there an easier way to do it with text? Can I have a table without figure axes?

0 Comments

Brad

Products

No products are associated with this question.

3 Answers

Answer by Doug Hull on 11 May 2012
Accepted answer

I think you are looking for this:

UITABLE

1 Comment

Brad on 17 May 2012

Thank Doug. It is actually a little more than I need, but it works well. One further question - I have column headings that I store, as per the Mathworks examples for uitable, in curly brackets:
coltitles={'\delta^{47}','\delta^{48}','\delta^{49}','\delta^{13}C',...etc.}
The problem is that these are not converted into Greek symbols and super/subscripts on the table output. Why are text entries coded differently in uitable? Is it the way I have stored the variables? I have tried square brackets (a matrix of text entries), and that has the problem of simply printing every heading into one cell of the table.

Thanks,
Brad

Doug Hull
Answer by Matthew on 11 May 2012

I recently worked this out for my personal case - UITABLE is great, but did not give me the look I wanted. Here is what I did:

NOTE: Using Courier is good for the justification issues to get text aligned.

% Convert to text
intCellString = cell([size(sub_rmsint_tab,1) 1]);
for ii = 1:size(sub_rmsint_tab,1)
    thisRow = [];
    for jj = 1:size(sub_rmsint_tab,2)
        if isnan(sub_rmsint_tab(ii,jj))
            thisRow = [thisRow '           '];
        else
            %thisRow = [thisRow sprintf('%7.0f',sub_rmsint_tab(ii,jj))];
            thisRow = [thisRow sprintf('%7.0f\t',sub_rmsint_tab(ii,jj))];
        end
    end
    intCellString{ii,1} = thisRow;
end
% Convert to text
depCellString = cell([size(sub_dep_tab,1) 1]);
for ii = 1:size(sub_dep_tab,1)
    thisRow = [];
    for jj = 1:size(sub_dep_tab,2)
        thisRow = [thisRow sprintf('%7.0f\t',sub_dep_tab(ii,jj))];
    end
    depCellString{ii,1} = thisRow;
end
x = -3;
y = -5;
subplot(1,3,3)
myBigTable = [{'             From Semblance Analysis'};...
    {'   TWTT   Depth  TWTT bsf Depth bsf Vint   Vrms'};...
    intCellString; {'    '};{'    '};{'    '};...
    {'             From Refraction Modeling'};...
    {'   TWTT   Depth TWTT bsf Depth bsf Vint    Vrms'}; ...
    depCellString];
t1 = text(x,y,myBigTable);
set(t1,'fontname','courier')
set(t1,'fontsize',6)
set(t1,'HorizontalAlignment','left')

1 Comment

Brad on 17 May 2012

This seems interesting, but it is a little too complicated to follow without the context of your code.

Matthew
Answer by Brad on 17 May 2012

re-iterating the comment I made to Doug above (in case an answer generates more visibility than a comment)

I have column headings that I store, as per the Mathworks examples for uitable, in curly brackets:

coltitles={'\delta^{47}','\delta^{48}','\delta^{49}','\delta^{13}C',...etc.}

The problem is that these are not converted into Greek symbols and super/subscripts on the table output. Why are text entries coded differently in uitable? Is it the way I have stored the variables? I have tried square brackets (a matrix of text entries), and that has the problem of simply printing every heading into one cell of the table.

4 Comments

Brad on 18 May 2012

Thank you Walter, I will try this. Quick question on your answer - Why? Why HTML when most other things are Latex?

Brad on 18 May 2012

Now the question is more like Why!!!?!?!??? #$!@! Your suggestion generates the following error before execution of the M-file:

??? Error: File: DPClumped.m Line: 81 Column: 17
Unexpected MATLAB expression.

These are lines of code I tried:
del = '<HTML>&delta;<sup>' ;
Del = '<HTML>&Delta;<sub>';
coltitles={[del'47'],[del'48'],[del'49'],[del'13' C],...
[del'18' O],[Del'47-[EGvsWG]'],[Del'48-[EGvsWG]'],...
[Del'49-[EGvsWG]'];

Norman Koren on 1 Mar 2013

It worked well for me when I used a well-formed HTML expression:

 '<HTML>&Delta;</HTML>' 

But frustrating that it's inconsistent with the rest of Matlab and not well documented (I'd be out of luck if it weren't for this post).

Brad

Contact us