Code covered by the BSD License  

Highlights from
tdfwrite (export data in Tab delimited format)

Be the first to rate this file! 12 Downloads (last 30 days) File Size: 1.62 KB File ID: #25622

tdfwrite (export data in Tab delimited format)

by Rafael Palacios

 

20 Oct 2009 (Updated 22 Oct 2009)

The structure returned by tdfread (Statistics tbx) can be stored with tdfwrite.

| Watch this File

File Information
Description

Matlab comes with a function called tdfread, which is one of the best functions for reading text files because it can handle numerical and textual data.
It reads textfiles with a header (to describe each column) and many rows of data. It surpasses Excel limitations with large number of rows.
tdfread creates a structure with as many fields as columns in the file, using column names as field names.

Unfortunately Matlab does not provide tdfwrite, so here it is.
It is as simple as tdfread and does exactly the opposite. It generates a textfile, creating a header with structure field names, then stores the data in textual format.

function tdfwrite(filename,st)
 
st is a structure created with st=tdfread('file.tab');
st is a structure with several fields. Each field is a vector of numbers or a matrix of char.

Example:
If the file textfile.tab is the following:
Latitude » Longitude » City
42.3584 » -71.0598 » Boston
40.4167 » -3.7003 » Madrid
41.8955 » 12.4823 » Rome

You can use
>> z=tdfread('textfile.tab');
>> tdfwrite('newfile.tab',z);

Then newfile.tab will look like this:
Latitude » Longitude » City
42.358400000000003 » -71.059799999999996 » Boston
40.416699999999999 » -3.7002999999999999 » Madrid
41.895499999999998 » 12.4823 » Rome

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
22 Oct 2009

Corrected Tags in description

22 Oct 2009

tdfread is not part of standard Matlab, it is only available with statistics toolbox.
tdfwrite works in any Matlab configuration

Tag Activity for this File
Tag Applied By Date/Time
data export Rafael Palacios 22 Oct 2009 12:32:59
ascii files Rafael Palacios 22 Oct 2009 12:32:59
text files Rafael Palacios 22 Oct 2009 12:32:59

Contact us at files@mathworks.com