Home > FMAToolbox > Plot > TableFigure.m

TableFigure

PURPOSE ^

TableFigure - Create table figure.

SYNOPSIS ^

function [f,t] = TableFigure(title,data,columns)

DESCRIPTION ^

TableFigure - Create table figure.

  USAGE

    [f,t] = TableFigure(title,data,columns)

    title          table title
    data           cell array of strings to populate the table
    column         optional cell vector of column names

  OUTPUT

    f              figure handle
    t              table object

  SEE

    See also HTML for table cell format.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [f,t] = TableFigure(title,data,columns)
0002 
0003 %TableFigure - Create table figure.
0004 %
0005 %  USAGE
0006 %
0007 %    [f,t] = TableFigure(title,data,columns)
0008 %
0009 %    title          table title
0010 %    data           cell array of strings to populate the table
0011 %    column         optional cell vector of column names
0012 %
0013 %  OUTPUT
0014 %
0015 %    f              figure handle
0016 %    t              table object
0017 %
0018 %  SEE
0019 %
0020 %    See also HTML for table cell format.
0021 
0022 % Copyright (C) 2013 by Michaƫl Zugaro
0023 %
0024 % This program is free software; you can redistribute it and/or modify
0025 % it under the terms of the GNU General Public License as published by
0026 % the Free Software Foundation; either version 3 of the License, or
0027 % (at your option) any later version.
0028 
0029 if nargin < 2,
0030     error('Incorrect number of parameters (type ''help <a href="matlab:help TableFigure">TableFigure</a>'' for details).');
0031 end
0032 if nargin < 3,
0033     columns = cell(1,size(data,2));
0034 end
0035 
0036 if size(columns,2) ~= size(data,2),
0037     error('Incompatible data and column sizes (type ''help <a href="matlab:help TableFigure">TableFigure</a>'' for details).');
0038 end
0039 
0040 titleHeight = 20;
0041 
0042 f = figure;
0043 pos = get(f,'position');
0044 uicontrol('style','text','position',[0 pos(4)-titleHeight pos(3) titleHeight],'string',title);
0045 p = uipanel('position',[0 0 pos(3) pos(4)-titleHeight]);
0046 t = uitable('ColumnName',columns,'position',[0 0 pos(3) pos(4)-titleHeight],'data',data,'parent',p);
0047 
0048 % Adjust column widths to contents
0049 
0050 % Determine maximum width in each column
0051 widths = max(cellfun(@(x) length(num2str(x)),[data;columns]));
0052 % Convert to pixels
0053 a1 = get(t,'extent');
0054 a1 = a1(3);
0055 set(t,'units','points');
0056 a2 = get(t,'extent');
0057 a2 = a2(3);
0058 set(t,'units','pixels');
0059 widths = round(1.2*widths/a1*a2*get(t,'fontsize'));
0060 widths = num2cell(widths);
0061 % Which columns contain numbers?
0062 numbers = logical(sum(cellfun(@isnumeric,data)));
0063 % Leave these columns in 'auto' mode
0064 widths(numbers) = {'auto'};
0065 % Adjust
0066 set(t,'ColumnWidth',widths);

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005