Read a textfile with textscan

  • Follow


Hi.
I need to read a text file by lines, storing the result in a
cell array of string like the textread function does. The
problem is each line is compound of various strings
separated by whitespaces, and I want to retrieve the whole
content of each line, not as separated strings.
I think it can't be done with textread so I've tried with
textscan. But now the problem is that texscan returns a cel
array and I need a cell array of strings. How could I
convert it to an array of strings?
Thanks a lot.
0
Reply asdf209 (154) 5/26/2008 7:04:02 AM

"Dani " <asdf@asdf.com> wrote in message
<g1dnd2$t67$1@fred.mathworks.com>...
> Hi.
> I need to read a text file by lines, storing the result in a
> cell array of string like the textread function does. The
> problem is each line is compound of various strings
> separated by whitespaces, and I want to retrieve the whole
> content of each line, not as separated strings.
> I think it can't be done with textread so I've tried with
> textscan. But now the problem is that texscan returns a cel
> array and I need a cell array of strings. How could I
> convert it to an array of strings?
> Thanks a lot.

Use the proper delimiter:

S = textread('file.txt','%s','delimiter','\n')

hth
Jos

0
Reply DELjos (627) 5/26/2008 7:12:01 AM


"Jos " <DELjos@jasenDEL.nl> wrote in message
<g1dns1$32u$1@fred.mathworks.com>...
> "Dani " <asdf@asdf.com> wrote in message
> <g1dnd2$t67$1@fred.mathworks.com>...
> > Hi.
> > I need to read a text file by lines, storing the result in a
> > cell array of string like the textread function does. The
> > problem is each line is compound of various strings
> > separated by whitespaces, and I want to retrieve the whole
> > content of each line, not as separated strings.
> > I think it can't be done with textread so I've tried with
> > textscan. But now the problem is that texscan returns a cel
> > array and I need a cell array of strings. How could I
> > convert it to an array of strings?
> > Thanks a lot.
> 
> Use the proper delimiter:
> 
> S = textread('file.txt','%s','delimiter','\n')
> 
> hth
> Jos
> 
Thank you.
I thought textread only accepted filename and format parameters.
0
Reply asdf209 (154) 5/26/2008 8:47:02 AM

2 Replies
65 Views

(page loaded in 0.032 seconds)

Similiar Articles:













7/8/2012 1:01:19 PM


Reply: