Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Read tab delimited files with header file

22 views
Skip to first unread message

edward kabanyas

unread,
May 27, 2012, 10:05:07 PM5/27/12
to
Dear all;

I have two types of tab delimited files, first separated with ' ' or 'space' and ';' or 'semi'. All files are in CSV type and have a header file which is not variable names separated by the tabs.

For the first type (separated with space), I read as:

fid = fopen(fname1);
fmt=['%s %s %f %f %d %s %s %f %d %d %d %d %f %f %s' repmat('%8.1f',1,1024) '%s'];
data = textscan(fid,fmt,'HeaderLines',1,'Delimiter',',','CollectOutput',1);

However, for the second type (separated with ';') I have problem to read it.
I tried to use tdfread, but the header file is not variable names separated by the tabs and the number of header column is not the same as the second row (data). In another data, data separated with ';' are without header file.

Probably you have expecrience in reading this kind of data, separated with ';' but without variable names in the first row.

Thank you,

Edward

TideMan

unread,
May 27, 2012, 10:45:56 PM5/27/12
to edward kabanyas
Just replace comma with semicolon in delimiter and remove headerlines:
data = textscan(fid,fmt,'Delimiter',';','CollectOutput',1);

edward kabanyas

unread,
May 27, 2012, 10:51:06 PM5/27/12
to
For the second type (separated with ';'), I try as follow:


fmt=repmat(';',1,1039);
data = tdfread(fname1,fmt);

However, because the header file is not variable names separated by the tabs, the data structure is not correct. Thanks for help,

Edward


"edward kabanyas" <djuk...@yahoo.com> wrote in message <jpumgj$rru$1...@newscl01ah.mathworks.com>...

edward kabanyas

unread,
May 27, 2012, 11:03:06 PM5/27/12
to
TideMan,

Thanks for your reply.

Your solution is very nice, it works. However, suppose I have many lines data in a file as below:

28.05.2011;00:00:00;2.161;20.60;58;+RADZ;RL+;24.645;5156;11064;178;14;0.06;24.....and soon

28.05.2011;00:00:10;2.349;20.60;58;+RADZ;RL+;25.392;4643;11057;187;15;0.06;24...and soon

the first and the second line is separated with a space (empty line), probably you have other suggestion to read it. Thanks again for help,

Edward


<mul...@gmail.com> wrote in message <941e5419-42fe-41c6...@googlegroups.com>...
0 new messages