×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to parse large text files

How to parse large text files

How to parse large text files

(OP)
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.

RE: How to parse large text files

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources