How to create a decent looking report

21 views (last 30 days)
Hi,
I'm having a lot of trouble creating a decent looking final report in Matlab. The, rather bad, way I'm currently doing it is to create a GUI window, 'print' that window, and then save that as an image or a PDF:
This looks decent enough but has a lot of problems like the GUI refusing to be the size I set it as (namely A4 size, it automatically resizes to something that fits on the user's screen) and if the user's resolution or DPI is different to the one I have then, regardless of setting all the sizes in normalized units, boxes/text get moved around, squished, cut off, and it just looks bad in general.
I tried creating something similar using the included report generator in Matlab, but I could not figure out how to use the generator at all. Even the very first thing I tried, the title, proved to be impossible since I couldn't figure out how to center the text, or change its size, or remove the 'Chapter 1.' preface when using the chapter/section blocks.
Then I spent the entire week trying to make my current attempt using a GUI made with GUIDE work properly in different scenarios and made literally no progress whatsoever.
Today I messed around with the code publishing feature which made excellent pdf, word and html documents, but sadly was clearly not designed for my use case. Is there a way to use the code publisher's document creation features outside of the publisher? One idea I had was to just write all the values I want, like name, date, etc..., to a .m file using a function, then publish that .m, but that seems like a really hacky roundabout way of doing it.
Right now the only other option I can think of is to create a .tex template and have a function in matlab search through that template substituting in things like PutNameHere for the name, and inserting .png images into the tex code, then using the command line function to compile the modified tex template. But this means the user would have to install additional latex compilers too.
Is there really no decent way to create a good looking report in matlab, or am I just missing something? I quite like the layout of my stupid GUI-based report, but it doesn't produce the same report on computers with different screens and doesn't even have proper A4 dimensions.
Does anybody have any advice or is my best bet to write a function which searches through a .tex file, substitutes in bits of code and then compiles to pdf? Since that seems like a really stupid way to do it as well.
Thanks for any help,
Robert
  3 Comments
Robert Rosca
Robert Rosca on 29 Jul 2016
Oops, thanks anyway, least I can do is not have typos.
ARN
ARN on 20 Dec 2018
Hi Robert,
I have a question if u have time.
Did u code the GUI file or did u just make a .m file and plot the figures in GUI. As i want to do the later thing but don't know how to do it

Sign in to comment.

Accepted Answer

Robert Rosca
Robert Rosca on 30 Aug 2016
Edited: Robert Rosca on 30 Aug 2016
In case anybody has a similar problem to mine, after trying a few different things it turns out that the best way to do this was to:
1. Install MiKTeX
2. Use Matlab's fopen to create a .tex file
3. Use fprintf to write LaTeX code to that file, as an example my LaTeX header was:
fprintf(tempfile, '%s\n', '\documentclass{article}', '\usepackage[utf8]{inputenc}', '\usepackage{graphicx}', '\usepackage[T1]{fontenc}',...
'\usepackage{lmodern}', '\usepackage{multicol}', '');
fprintf(tempfile, '%s\n', '\usepackage{geometry}', ' \geometry{', ' a4paper,', ' tmargin = 1cm,',...
' lmargin = 2cm', '}', '');
4. I'm certain there's a better way to do this, but for text which changes I used:
NameString = ['Name: ', PatientName];
fprintf(tempfile, '%s\n', NameString, '');
5. End the document and close the file:
fprintf(tempfile, '%s\n', '\end{document}');
fclose(tempfile);
6. Use the latex system() function to run a pdflatex command to compile your .tex file (-interaction=nonstopmode is needed otherwise the system() function will never end since it's waiting for user input, which doesn't come since no terminal window opens):
savecommand = [[Directory(1) ':'] ' && ' ['cd "' Directory] '" && ' 'pdflatex ' ['"' Directory TexFileName '"'] ' -interaction=nonstopmode'];
[status, cmdout] = system(savecommand);
7. Finally I deleted the temporary .tex file, as well as any images created for the report.
This seems to be the best way to get a consistent, good looking report.

More Answers (0)

Categories

Find more on MATLAB Report Generator 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!