Thread Subject: how to read the whole file into a string?

Subject: how to read the whole file into a string?

From: Arthur Zheng

Date: 13 Jul, 2009 14:55:08

Message: 1 of 4

how to read the whole file into a single string including the whitespace and newline?

The file looks like :
AAur_0001 dnaA 1 1..1419 1419
AAur_0002 dnaN 1995 1995..3119 1125
AAur_0003 3224 3224..4108 885
AAur_0004 recF 4132 4132..5331 1200

Note I want the result in a single string, not several strings. Can I use textread or any other function? thanks.

Subject: how to read the whole file into a string?

From: Leslie McBrayer

Date: 13 Jul, 2009 15:01:19

Message: 2 of 4


"Arthur Zheng" <hzheng7@gatech.edu> wrote in message
news:h3fhsc$5h7$1@fred.mathworks.com...
> how to read the whole file into a single string including the whitespace
> and newline?
>
> The file looks like :
> AAur_0001 dnaA 1 1..1419 1419
> AAur_0002 dnaN 1995 1995..3119 1125
> AAur_0003 3224 3224..4108 885
> AAur_0004 recF 4132 4132..5331 1200
>
> Note I want the result in a single string, not several strings. Can I use
> textread or any other function? thanks.

help fileread

Subject: how to read the whole file into a string?

From: Rune Allnor

Date: 13 Jul, 2009 15:05:31

Message: 3 of 4

On 13 Jul, 16:55, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> how to read the whole file into a single string including the whitespace and newline?
>
> The file looks like :
> AAur_0001       dnaA    1       1..1419 1419    
> AAur_0002       dnaN    1995    1995..3119      1125    
> AAur_0003               3224    3224..4108      885    
> AAur_0004       recF    4132    4132..5331      1200
>
> Note I want the result in a single string, not several strings. Can I use textread or any other function? thanks.

Bad idea. If the file is small, you will not gain any
significant speed by doing this. If the file is large,
you might gain speed but end up in 'Out of Memory' type
problems. The best strategy is to use a file buffer
of moderate size (say, 10 MBytes), and read the file
in chunks. I have no idea of how to do this in matlab,
though.

If the file is large and speed is a concern, you might
want to port to C or C++. The newest C++ standard (I don't
know about C) has support for regular expressions included,
so you will be able to use the stuff you already have with
only minor modifications. Both C and C++ allows some
manipulation of I/O buffer sizes, so you can gain a bit of
speed while keeping memory usage under control.

Rune

Subject: how to read the whole file into a string?

From: Arthur Zheng

Date: 13 Jul, 2009 15:08:02

Message: 4 of 4

"Leslie McBrayer" <lmcbrayer@mathworks.com> wrote in message <h3fi80$68$1@fred.mathworks.com>...
>
> "Arthur Zheng" <hzheng7@gatech.edu> wrote in message
> news:h3fhsc$5h7$1@fred.mathworks.com...
> > how to read the whole file into a single string including the whitespace
> > and newline?
> >
> > The file looks like :
> > AAur_0001 dnaA 1 1..1419 1419
> > AAur_0002 dnaN 1995 1995..3119 1125
> > AAur_0003 3224 3224..4108 885
> > AAur_0004 recF 4132 4132..5331 1200
> >
> > Note I want the result in a single string, not several strings. Can I use
> > textread or any other function? thanks.
>
> help fileread
>
thanks

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
read file textr... Arthur Zheng 13 Jul, 2009 10:59:04
rssFeed for this Thread

Contact us at files@mathworks.com