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 :)
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.
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.
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 ?
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);
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.
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'.
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.