Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

How to parse large text files

Status
Not open for further replies.

Guest
I need to parse a large text file and import the data that I parse into another file. The data I need to parse is 169 rows by 4 columns, and I need to parse this data 12 times throughout the file. The data that I need to parse into another output file is also large. I am new with using matlab and would appreciate any help.

I was thinking of using fscanf, but am unsure of how to parse past the unwanted text in the file, and to just save the 169 * 4 data into another file.
 
Replies continue below

Recommended for you

To read a header
hdr = char(textread(fname,'%[^\n]',nlines));
to read any header lines. (fname='file.txt', nlines=3)

To read column data use
data=dlmread(fname,delimiter,[r1 c1 r2 c2])
delimiter=' ,\t'
r1 is the starting row
c1 is the starting column
r2 is the ending row
c2 is the ending column

Use the data command as many times as needed (4).

Cheers
John V.
 
Status
Not open for further replies.
Back
Top