comparison textTable.m @ 286:fdee7f66a5e9 feature/textTable

plainTextTable working.
author Martin Almquist <martin.almquist@it.uu.se>
date Mon, 12 Sep 2016 14:10:40 +0200
parents 3c25601f1fe3
children
comparison
equal deleted inserted replaced
271:3c25601f1fe3 286:fdee7f66a5e9
1 1
2 % data -- cell array of strings for each cell 2 % data -- cell array of numbers
3 function textTable(data,divCol, divColWeight, divRow, divRowWeight) 3 % leftColstrings -- cell array of strings, for left column
4 % topRowStrings -- cell array of strings, for top row
5 % dataFormat -- (optional) format specifier, e.g. '%.2f'
6 function textTable(data, leftColStrings, topRowStrings, dataFormat)
7
8 default_arg('dataFormat','%.2f')
9
10 nRows = length(leftColStrings);
11 nCols = length(topRowStrings);
12 [m,n] = size(data);
13
14 if(m ~= nRows || n ~=nCols)
15 error('Data dimensions must match labels');
16 end
4 17
5 % Find column widths 18 % Find column widths
6 colWidth = {}; 19 headerLength = 0;
7 for i = 1:size(data, 2) 20 for i = 1:nCols
8 for j = 1:size(data, 1) 21 headerLength = max(headerLength, length(topRowStrings{i} ));
9 c(j) = length(data{j,i}); 22 end
23
24 dataLength = 0;
25 for i = 1:nRows
26 for j = 1:nCols
27 temp = length(sprintf(dataFormat, data{i,j}));
28 dataLength = max(dataLength, temp);
10 end 29 end
11 colWidth{i} = max(c);
12 end 30 end
31 dataLength = length(sprintf(dataFormat, data{1,1}));
32
33 colWidth = max(headerLength,dataLength);
13 34
14 error('not done') 35 % Print headers
15 36 fprintf(' %*s |',colWidth,'')
16 eW = 0; 37 for i = 1:nCols
17 qW = 0; 38 fprintf(' %-*s |', colWidth, topRowStrings{i});
18 for i = 1:length(orders)
19 log_e{i} = log10(e{i});
20 eW = max(eW, findFieldWidth('%.2f',log_e{i}));
21 qW = max(qW, findFieldWidth('%.2f',q{i}));
22 end
23
24 mW = findFieldWidth('%d',m);
25 orderHeaderWidth = eW + qW + 1;
26
27 fprintf('method: %s\nT: %d\n',methodName, T);
28
29 % Print order headers
30 fprintf(' %*s |',mW,'')
31 for i = 1:length(orders)
32 fprintf(' %-*s |', orderHeaderWidth, sprintf('Order %d', orders{i}));
33 end 39 end
34 fprintf('\n'); 40 fprintf('\n');
35 41
36 42 % Print divider
37 % Print eq headers 43 m_dev = repmat('-',1,colWidth);
38 fprintf(' %*s |',mW,'m'); 44 column_dev = repmat('-',1,colWidth);
39 for i = 1:length(orders)
40 fprintf(' %*s %*s |', eW, 'e', qW, 'q');
41 end
42 fprintf('\n');
43
44
45 % Print devider
46 m_dev = repmat('-',1,mW);
47 column_dev = repmat('-',1,orderHeaderWidth);
48 fprintf('-%s-+',m_dev); 45 fprintf('-%s-+',m_dev);
49 for i = 1:length(orders) 46 for i = 1:nCols
50 fprintf('-%s-+', column_dev); 47 fprintf('-%s-+', column_dev);
51 end 48 end
52 fprintf('\n'); 49 fprintf('\n');
53 50
54
55 51
56 % Print each row 52 % Print each row
57 for i = 1:length(m) 53 dataFormat = ['%*' dataFormat(2:end)];
58 fprintf(' %*d |',mW,m(i)); 54 for i = 1:nRows
59 for j = 1:length(orders) 55 fprintf(' %*s |',colWidth,leftColStrings{i});
60 if i == 1 56 for j = 1:nCols
61 fprintf(' %*.2f %*s |', eW, log_e{j}(i), qW, ''); 57 fprintf([' ' dataFormat ' |'], colWidth, data{i,j});
62 else
63 fprintf(' %*.2f %*.2f |', eW, log_e{j}(i), qW, q{j}(i-1));
64 end
65 end 58 end
66 fprintf('\n'); 59 fprintf('\n');
67 end 60 end
68 61
69 fprintf('\n'); 62 fprintf('\n');