4.8 | 4 ratings Rate this file 27 Downloads (last 30 days) File Size: 11.9 KB File ID: #24766
image thumbnail




17 Jul 2009 (Updated )

store data in a table format that supports printing in plain text, Latex, HTML, Wiki,...

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

DataTable objects are used to store data in a table format that is easily expandable, manipulatable and that supports printing in a variety of formats (plain text, Latex, HTML, Wiki; new printing formats can be added without changing any code). The format of numeric table contents (e.g. number of displayed digits) and the alignment of text and numbers can be changed for each column individually.

To use, extract zip-archive and add the extracted folder ('datatablepackage') to your matlab path.

Type 'help DataTable' for more information and examples on how to use DataTable.

The new object-oriented programming in MATLAB 7.6 (R2008a) or higher is required for DataTable to work.


This file inspired Forecasting The Ftse 100 With High Frequency Data: A Comparison Of Realized Measures and Table Class.

MATLAB release MATLAB 7.6 (R2008a)
Other requirements MATLAB 7.6 (R2008a) or higher
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
29 Nov 2011 Yuri K

Paul, thank you. Sorry for the late answer, I missed your reply.
Your solution leaves spaces on both sides of the delimiter. So it's actually
0.8147<space><tab><space>0.9134 etc.

13 Nov 2011 Paul Mattern

Hi Yuri, thanks for your comment! Simple tab-delimited tables can already be made with current version:
>> dt = DataTable();
>> dt{1:3,1:3} = rand(3);
>> dt.toText('delimiter', char(9)) % char(9) is a tab

0.8147 0.9134 0.2785
0.9058 0.6324 0.5469
0.1270 0.0975 0.9575

Or are you looking for something else?

02 Nov 2011 Yuri K

Paul, thanks for the great submission!

I don't think you need lines 448-451 since you process empty table inside the printer anyway.

I made a very simple TextFilePrinter to output the table to standard tab delimited text file. Hope you'd consider to include such functionality into the package.

03 Aug 2011 Paul Mattern

Hi Nicholaus,

the short answer is no, right now the TablePrinters get no information about the line number they are printing. So, it would require quite a bit of recoding to make it work. You could however use a (rather ugly) hack to get that extra \hline:

dt = DataTable();

... % fill table here

tmp = dt.getData(1,end);
dt{1,end} = sprintf('%g \\\\ \\hline %%', tmp{1});


This might be enough for some quick printing of results, but of course it destroys the nice look of the table if you print it in any other format than Latex.

If some more people request a feature like this I may add it when I find some time.

03 Aug 2011 Nicholaus Halecky

Hey Paul,
Thanks much for this great function -- I have just implemented it for printing some results and it is working quite well. Quick question, I use latex often and was wondering if it is easy to make basic changes to the Latex TablePrinter class/method -- specifically, I wanted to have the option to an \hline after the first row, thus distinguishing row titles from the datasets. Any thoughts?
I really appreciate it.
Thanks again.

05 Aug 2010 Torfinn

I was just looking to do this myself, luckily you saved me some time! One thing I had to modify for my use though: I wanted to print the table as a comment, thus I had to insert a '%' as a prefix for every line. I think an extra parameter to give prefixes would be useful for others as well.

18 Sep 2009 Matthew  
17 Aug 2009 Paul Mattern

Thanks for the comment. I just submitted the new version and it should be available shortly.

For a quick fix replace line 933 in DataTable.m:
strdata = myformat(this.applyColumnFormat());
strdata = this.standardFormat(this.applyColumnFormat());

More infos about the bug: The function "myformat" only exists on my computer and has been replaced by standardFormat in the DataTable class. Unfortunately I did not replace it everywhere.

14 Aug 2009 Kevin

I get this error when I try to run the code with the following.

>> table=DataTable();
>> table{1:10,1:10}=3

10x10 DataTable
??? Undefined function or method 'myformat' for input arguments of type 'cell'.

Error in ==> DataTable>DataTable.printTableBody at 933
strdata = myformat(this.applyColumnFormat());

Error in ==> DataTable>DataTable.toText at 211
this.printTableBody(fid, tight, TextTablePrinter(delimiter))

Error in ==> DataTable>DataTable.display at 921

17 Aug 2009

"Undefined function or method 'myformat' for input arguments of type 'cell'."

Contact us