0001 function [f,t] = TableFigure(title,data,columns)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
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
0049
0050
0051 widths = max(cellfun(@(x) length(num2str(x)),[data;columns]));
0052
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
0062 numbers = logical(sum(cellfun(@isnumeric,data)));
0063
0064 widths(numbers) = {'auto'};
0065
0066 set(t,'ColumnWidth',widths);