File Exchange

image thumbnail

Printing a formatted table

version 1.19 (13.8 KB) by

Allows to display and print simple text tables in MatLab. Plain and LaTeX format supported.

15 Downloads

Updated

View License

@@ ATTENTION @@
I've merged my separate submissions into KerMor/matlabtools (http://de.mathworks.com/matlabcentral/fileexchange/52299-kermor-matlabtools), which contains this submission. Please refer to that package to retrieve the current status.
@@@@
This class allows to display and print a table with arbitrary number of columns.

The first row can be distinguished from others by a HasHeader flag and the column separator string can be customized.

Basic automatic conversion allows to pass common, easily string-representable data types, and optionally sprintf-compatible format strings or callbacks can be passed for either all entries or entry-specific.

Optionally a caption can be added to the PrintTable upon construction, directly taking sprintf-like arguments.

Allows to save the table in the formats 'txt' (plain text), 'tex' (LaTeX tabular) and 'pdf' (Basically using pdflatex on 'tex' output).

The table can easily be transposed and sorted.

In difference to the submission #33717 I make use of classes and have more possibilities regarding output and appearance.

Now a basic automatic $Math$-Environment detection for LaTeX is available.

Comments and Ratings (14)

Andres Mora

Thanks man! Nice class. Saved me a bunch of time.. Latex included is an excellent bonus. Really easy to use.

Daniel Wirtz

Daniel Wirtz (view profile)

Hey Tintin,
well this case is simple: You need the pdflatex binary available on the PATH environment variable. I'm not a mac user, but i reckon there will be some terminal/shell script or even GUI-enabled way to specify your system's PATH variable.
you can see if it is set up correctly by running "!pdflatex --version" from within matlab.

Tintin Milou

Hi,

I don't fully understand how the pdf conversion works. I've got the latest version of mactex installed, but apparently, I need something else because I get the following error:
/bin/bash: pdflatex: command not found

Do I have to install something else and put it on the matlab path?
Thanks!

Daniel Wirtz

Daniel Wirtz (view profile)

Hey Mathias,
i dont see the point why you would want to sort data in a table without also moving the line headers to the correct position? correct me if i'm getting you wrong here..

Mathias

Hello, I just tested the sort function. It worked as expected exept that the Header-Line of the table is sorted too. Can one exclude the first line (if HasHeader == true or something similar) ?

Daniel Wirtz

Daniel Wirtz (view profile)

Hey Mathias,
thanks! I've just submitted a version also allowing simple alphanumeric sorting of specified columns.

Mathias

I love this Class. Excellent work. Would it be possible to have a sort method for the table (something like sortrows)?

Daniel Wirtz

Daniel Wirtz (view profile)

Hey Arnold,
unfortunately i do not have 2012b yet, so i haven't tested it with that version.
However, i figured that the critical point in formatting is the tab character equivalent in whitespaces, this setting somehow seems to be different amongst platforms/matlab versions.
I've submitted an updated version with improved autodetection of that constant.
see if this solves your issue, and if not, could you send me a private message with the generated output and commands you used?
thanks!

arnold

arnold (view profile)

I must be doing something wrong, the text output I see in the command window is not formatted at all?! Neither 'tex' or 'txt' seems to work.
Updated to 2012b, maybe that has something to do with it?

David Hagan

Daniel Wirtz

Daniel Wirtz (view profile)

Dear Colin,
i've just submitted an updated version with PDF support. Thank you for this suggestion!
Regarding the capitalization: I'm sticking with (what i think to be) the default Java rules for class member names; properties start with captial letter and functions start with small letters, both written in CamelCase.
As i'm programming this style everywhere i probably won't change it anytime soon, sorry :-)

Colin

Colin (view profile)

Fantastic tool, latex output is exactly what I was looking for.

Some (extremely minor) suggestions:
i. found the captilisation of the methods a bit hard to predict. e.g.

- t.print vs. t.Format vs t.addRow

which meant I had to keep referring to the help file to find out if it was t.print or t.Print

ii. command to output table straight to pdf:

e.g. if~exist('./TeX/','dir');mkdir('./TeX/');end
fid = fopen('./TeX/main.tex','w+');

fprintf(fid,'\\documentclass{article}\n\\begin{document}\n');
t.print(fid);
fprintf(fid,'\n\n\\end{document}');
fclose('all');

! pdflatex -output-directory ./TeX/ main.tex
open([pwd '/TeX/main.pdf'])

Sven

Sven (view profile)

Very nice tool! Usage is quite easy and the tex output might save me a lot of time. Well done!

Sven

Sven (view profile)

Updates

1.19

I've merged my separate submissions into KerMor/matlabtools (http://de.mathworks.com/matlabcentral/fileexchange/52299-kermor-matlabtools), which contains this submission. Please refer to that package to retrieve the current status.

1.19

Added a simple "sort" function

1.18

Bugfix for PrintTable LaTeX Table generation (printTex would throw an error sometimes)

1.16

- Stripping newlines automatically
- Soem verbose comments for LaTeX output about creating script

1.15

- bugfix for $$ wrapping also in txt mode
- added "append" method to join two tables

1.14

-New property "TexMathModeDetection" for cell content wrapping with $$
-New property "StripInsertedTabChars" for automatic stripping of tab chars
- Added a short comment of the applied settings to LaTeX output.
- Smaller improvements

1.13

Improved compatibility (no more wiggles ~)

1.12

Improved automatic TabCharLength computation

1.9

- More datatypes handled for "stringification"
- No more table title for TightPDF LaTeX export (one line)

1.8

- Added a ctranspose overload
- TabCharLen now public property
- Small fixes

1.5

-Saving to PDF now possible
-Option "TightPDF" for pdf to contain only actual table or be an article page
-HasRowHeader tag for easy formatting of non-first column entries
-Constructor takes caption with sprintf-arguments
-Bugfixes, Demos

1.4

Fixed some bugs and added LaTeX format output and optional captions to the PrintTable.

MATLAB Release
MATLAB 7.13 (R2011b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video