Export a large table to a pdf file

41 次查看(过去 30 天)
Kendell
Kendell 2024-8-8
回答: dpb 2024-8-8
I have a 16x23 table that I would like to export to a pdf through matlab. I have tried to turn the pdf to landscape to fit better, as well as reduce the text size. I have also tried to position it using "position" as an option in the function "uitable". I have also used the "print" function but it seems like saveas works better.
Essentially this is what I would like the output to look like (check the picture attached), but I want matlab to export and position it automatically after it runs. It can be in data form or table form.
Here is my current code:
fig = uifigure('Name','Value Averages');
t = table([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)], ...
[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)], ...
[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)], ...
[rand(16,1)],[rand(16,1)],'VariableNames',{'Number of Values','1st value','2nd value','3rd value','4th value', ...
'5th value','6th value','7th vlaue','8th value','9th value','10th value','11th value','12th value','13th value',...
'14th value','15th vlaue','16th value','117th value','18th value','19th value','20th value','21st value','22nd value'});
export = uitable(fig,"Data",t);
orient(fig,'landscape')
saveas(fig,'Value Averages.pdf','pdf')
  1 个评论
dpb
dpb 2024-8-8
t = table([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)], ...
[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)], ...
[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)],[rand(16,1)], ...
[rand(16,1)],[rand(16,1)],'VariableNames',{'Number of Values','1st value','2nd value','3rd value','4th value', ...
'5th value','6th value','7th vlaue','8th value','9th value','10th value','11th value','12th value','13th value',...
'14th value','15th vlaue','16th value','117th value','18th value','19th value','20th value','21st value','22nd value'});
Just as a "coding with MATLAB" tutorial, the above could be written more easily something like..
NV=22; % the total number of variables
NR=16; % the number rows
t=array2table([[1:NR].' rand(NR,NV)]);
t.Properties.VariableNames=["Number of Values","Value"+[1:NV]];
head(t)
Number of Values Value1 Value2 Value3 Value4 Value5 Value6 Value7 Value8 Value9 Value10 Value11 Value12 Value13 Value14 Value15 Value16 Value17 Value18 Value19 Value20 Value21 Value22 ________________ _______ _______ ________ _______ ________ _______ ________ ________ ________ _______ ________ ________ ________ _______ ________ _______ _________ _______ ________ _______ _______ ________ 1 0.20394 0.26226 0.88238 0.49906 0.001575 0.98607 0.023306 0.56308 0.43164 0.01982 0.95107 0.077816 0.87151 0.8457 0.16472 0.613 0.82721 0.28079 0.66759 0.34376 0.80316 0.58484 2 0.82904 0.87154 0.40181 0.12795 0.069359 0.14534 0.51539 0.71362 0.6455 0.28895 0.042876 0.5442 0.17411 0.86246 0.16002 0.79461 0.95475 0.8244 0.64815 0.98528 0.25729 0.21201 3 0.55671 0.52545 0.24969 0.75217 0.42609 0.99198 0.12909 0.74051 0.31355 0.86744 0.089412 0.646 0.018897 0.91642 0.20535 0.93555 0.28442 0.3581 0.50284 0.86841 0.78036 0.86315 4 0.10948 0.52632 0.31249 0.95311 0.55516 0.17619 0.39812 0.3767 0.93328 0.44319 0.29229 0.37526 0.4727 0.59668 0.68076 0.66118 0.20039 0.28391 0.87019 0.39073 0.75119 0.84054 5 0.79353 0.48791 0.62042 0.77671 0.7225 0.52792 0.12413 0.32494 0.052949 0.32374 0.81771 0.043962 0.97677 0.58249 0.16662 0.48197 0.0072422 0.44861 0.085944 0.20573 0.67123 0.52475 6 0.45029 0.2504 0.7167 0.61957 0.27068 0.1965 0.54358 0.89367 0.06519 0.9623 0.17688 0.065465 0.60425 0.19571 0.75863 0.64105 0.2114 0.3791 0.24088 0.41814 0.4315 0.064366 7 0.83803 0.55243 0.62519 0.89323 0.24501 0.14827 0.66168 0.096617 0.32616 0.40153 0.9628 0.69911 0.6659 0.4976 0.8702 0.46688 0.38588 0.92444 0.72207 0.17468 0.76466 0.53846 8 0.97845 0.54556 0.075017 0.41895 0.66114 0.92046 0.17053 0.31249 0.97132 0.98552 0.34129 0.27249 0.2299 0.5173 0.021362 0.19804 0.16386 0.86573 0.97135 0.82136 0.86503 0.66049
I did take the shortcut of creating the variable names without the numeric value-specific suffix, but while correct naming, those would turn out to be very painful to use in having to special-case them to refer the specific variables by name; the generic plain version will be much more convenient. I also didn't include the embedded blank; that is also programmatically more effort to deal with than it generally is worth. The table is not really intended to be a display object.

请先登录,再进行评论。

回答(1 个)

dpb
dpb 2024-8-8
The table isn't intended to be an output formatting tool; you can try exportgraphics and see if can get anywhere, but you may need the addon report generator to get satisfactory generic results. This is an area I've never eplored in depth...

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by