Code covered by the BSD License  

Highlights from
Converting MATLAB data to LaTex table

5.0

5.0 | 4 ratings Rate this file 87 Downloads (last 30 days) File Size: 3.59 KB File ID: #44274
image thumbnail

Converting MATLAB data to LaTex table

by

 

11 Nov 2013 (Updated )

Converts MATLAB data to fancy LaTex table code the easy way

| Watch this File

File Information
Description

An easy to use function that generates code for a LaTex table from a given numeric MATLAB array. It is also possible to use the new MATLAB datatype 'table' as data input. Optional parameters are available to control the data precision and other table properties. The LaTeX code is printed into the command window for quick copy&paste and also given back as a cell array for further processing in MATLAB. Enjoy :)

Required Products MATLAB
MATLAB release MATLAB 8.2 (R2013b)
Other requirements If you want to use a MATLAB table as data input, your MATLAB version needs to be r2013b or newer.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
10 Apr 2014 Eli Duenisch

The function works row-wise so the format for each data row is the same. You could tweak the code in section '% generate row-format cell array based on input.tableDataFormat' and then apply the format in section '% make table rows:'. I'm planning to implement switching between row-wise and cloumn-wise tables in my next update.

08 Apr 2014 Manuel

Is it possible to change the format of each single column differently like changing the format of each row ?

08 Apr 2014 Eli Duenisch

By now the function only supports multi-row headers. I'm planning to rewrite the code in a way that the whole table can be pivoted between row-based and cloumn-based. This would also cover multi-line and multi-row headers.

08 Apr 2014 Manuel

And is it possible to support utf8 signs ?

07 Apr 2014 Manuel  
07 Apr 2014 Manuel

Thank you very much...It works very well. I expected this way to be the solution but didn't find the right way to code it. Is it also possible to have multicolumn headers ?

07 Apr 2014 Eli Duenisch

Hi Manuel, yes it is possible. The function gives back a cell array containing the lines of the LaTex code. You can loop through this cell array and print the lines to a text document. Try something like this:

myCellArray = latexTable(input);
fid = fopen('myLatexFile.tex', 'wt+')
for i = 1 : size(myCellArray,1)
fprintf(fid, '%d%d%s\t\n', myCellArray{i,:});
end
fclose(fid);

07 Apr 2014 Manuel

Is it possible to output the code direktly to a .tex document from the command window ?? If not, how can I realize ?

22 Feb 2014 Eli Duenisch

It is now possible to use the new MATLAB datatype 'table' as data input.
Column headers are added as an optional input.

15 Feb 2014 Eli Duenisch

Hi Mehmet, it seems to me that your code is not providing the field input.tableData which contains the data that should be placed in a LaTex table. I just uploaded a script runExample.m that runs an example of how to use latexTable.m. Maybe you try to run this on your system and compare it with your code. Please let me know if the problem persists.

15 Feb 2014 Mehmet Niyazi ÇANKAYA

Hello,

I received error message

Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2 Release Notes, Assigning Nonstructure Variables As Structures
Displays Warning, for details.
> In latexTable at 65
Reference to non-existent field 'tableData'.

Please help how I can solve it.

09 Dec 2013 Pi Ting

useful

05 Dec 2013 Eli Duenisch

Hi Timo, thank you for your feedback. I have been thinking about the support of MATLAB tables and I will implement it in the update (in a week or so).

05 Dec 2013 Timo

Fantastic submission, Eli. A true time saver. Thanks! I am just getting to know the 2013b table function which so far looks really useful. Would it be possible to have latexTable accept a matlab table as an input? That would be amazing.

22 Nov 2013 Chris

It does the job quick and simple.Great!

Updates
21 Nov 2013

Now you can set a replacement value for NaNs in your MATLAB data, e.g. use an empty string for a blank space or '-' for a minus sign.

15 Feb 2014

Added a script to run an simple example of latexTable.m

15 Feb 2014

Changes in comment section

18 Feb 2014

Updated comments in example script

24 Feb 2014

It is now possible to use the new MATLAB datatype 'table' as data input.
Column headers are added as an optional input.

Contact us