Export a large table to a pdf file
40 views (last 30 days)
Show older comments
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 Comment
dpb
on 8 Aug 2024
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)
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.
Answers (1)
dpb
on 8 Aug 2024
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...
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!