Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Is there something faster than strread?

Subject: Is there something faster than strread?

From: Will Thompson

Date: 23 Jul, 2010 14:46:05

Message: 1 of 4

hey,

I am running a very data intensive project that requires parsing through very long text files and picking out information. To accomplish this, I have been using fgets to go line by line through the file and to look for this information with strread. However, this process is being very slow and it seems to be due to the sttread function.

Does anyone have a recommendation for a faster version of sttread?

Thanks,

will

Subject: Is there something faster than strread?

From: John Zoidberg

Date: 23 Jul, 2010 15:01:04

Message: 2 of 4

You could try using fileread to read in the whole file at once into one string.
That's what I did here:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287600

I'm not sure how well it works with huge files, but having everything already in memory should be faster in principle.

You could also try compiling the script into an exe using the matlab compiler:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/164864

Subject: Is there something faster than strread?

From: Andres

Date: 24 Jul, 2010 22:02:03

Message: 3 of 4

"Will Thompson" <williamthompson2010@u.northwestern.edu> wrote in message <i2c9vd$cmp$1@fred.mathworks.com>...
> hey,
>
> I am running a very data intensive project that requires parsing through very long text files and picking out information. To accomplish this, I have been using fgets to go line by line through the file and to look for this information with strread. However, this process is being very slow and it seems to be due to the sttread function.
>
> Does anyone have a recommendation for a faster version of sttread?
>
> Thanks,
>
> will

I suppose textscan is faster than the (outdated) strread.
It would be helpful if you give an example or some more details. E.g., do you need to get some information out of every line, or just from some of the lines? If, in the latter case, the lines of interest can be identified by some few keywords, it might be worth having a look at my file exchange submission txt2mat with its line filtering options (and probably read mode 'char' or 'cell', see the doc) to get around using fgets through the whole file (which isn't very fast either).
Good luck,
Andres

Subject: Is there something faster than strread?

From: Jan Simon

Date: 24 Jul, 2010 22:53:04

Message: 4 of 4

Dear Will,

> > I am running a very data intensive project that requires parsing through very long text files and picking out information. To accomplish this, I have been using fgets to go line by line through the file and to look for this information with strread. However, this process is being very slow and it seems to be due to the sttread function.

Please show us some relevant lines of the file and your STRREAD command. Without more details it is hard to guess, what might accelerate your program.

Kind regards, Jan

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us