Thread Subject: How to read many variables from a file?

Subject: How to read many variables from a file?

From: supandey@yahoo.com

Date: 2 Feb, 2009 04:16:18

Message: 1 of 5

Hello,

I have about 200 variables I need to read from a file

 [X1, X2, X3, ....X200] = textread("myFile.txt", '%f%f....%f')

 Can one make a loop to create the [X1,......,X200] to avoid a lot of
typing? I was thinking something
 with eval but its not obvious. Another solution would be to script
the output to
 a file and paste it back in, buts thats not elegant.

 Thanks,
 Sanjeev

Subject: How to read many variables from a file?

From: Husam Aldahiyat

Date: 2 Feb, 2009 04:55:03

Message: 2 of 5

supandey@yahoo.com wrote in message <a05054ca-821e-447e-a6fb-a57e966695ae@f40g2000pri.googlegroups.com>...
> Hello,
>
> I have about 200 variables I need to read from a file
>
> [X1, X2, X3, ....X200] = textread("myFile.txt", '%f%f....%f')
>
> Can one make a loop to create the [X1,......,X200] to avoid a lot of
> typing? I was thinking something
> with eval but its not obvious. Another solution would be to script
> the output to
> a file and paste it back in, buts thats not elegant.
>
> Thanks,
> Sanjeev

It's ok if you use eval, don't be afraid.

Subject: How to read many variables from a file?

From: Walter Roberson

Date: 2 Feb, 2009 06:09:49

Message: 3 of 5

supandey@yahoo.com wrote:

> I have about 200 variables I need to read from a file
>
> [X1, X2, X3, ....X200] = textread("myFile.txt", '%f%f....%f')

Why? Why aren't you using a cell array instead? Does your program
strictly rely upon the inputname() function or something like that?


--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: How to read many variables from a file?

From: supandey@yahoo.com

Date: 2 Feb, 2009 15:04:09

Message: 4 of 5

On Feb 2, 12:09=A0am, Walter Roberson <rober...@hushmail.com> wrote:
> supan...@yahoo.com wrote:
> > I have about 200 variables I need to read from a file
>
> > =A0[X1, X2, X3, ....X200] =3D textread("myFile.txt", '%f%f....%f')
>
> Why? Why aren't you using a cell array instead? Does your program
> strictly rely upon the inputname() function or something like that?
>
> --
> .signature note: I am now avoiding replying to unclear or ambiguous posti=
ngs.
> Please review questions before posting them. Be specific. Use examples of=
 what you mean,
> of what you don't mean. Specify boundary conditions, and data classes and=
 value
> relationships -- what if we scrambled your data or used -Inf, NaN, or com=
plex(rand,rand)?

The number of variables I read from the file changes each time I call
it. I am curious about your comment regarding using cell arrays.
Is it possible to do something like

Xcell =3D {=85=85}
[Xcell] =3D textRead(=85)

When I do that I get -

"??? Number of outputs must match the number of unskipped input
fields."

Regards,
Sanjeev

Subject: How to read many variables from a file?

From: Steven Lord

Date: 2 Feb, 2009 15:12:22

Message: 5 of 5


<supandey@yahoo.com> wrote in message
news:3d4465b7-c6eb-4f71-ad59-73b244a47086@t26g2000prh.googlegroups.com...
> On Feb 2, 12:09 am, Walter Roberson <rober...@hushmail.com> wrote:
> > supan...@yahoo.com wrote:
> > > I have about 200 variables I need to read from a file
> >
> > > [X1, X2, X3, ....X200] = textread("myFile.txt", '%f%f....%f')
> >
> > Why? Why aren't you using a cell array instead? Does your program
> > strictly rely upon the inputname() function or something like that?
> >
> > --
> > .signature note: I am now avoiding replying to unclear or ambiguous
> > postings.
> > Please review questions before posting them. Be specific. Use examples
> > of what you mean,
> > of what you don't mean. Specify boundary conditions, and data classes
> > and value
> > relationships -- what if we scrambled your data or used -Inf, NaN, or
> > complex(rand,rand)?
>
> The number of variables I read from the file changes each time I call
> it. I am curious about your comment regarding using cell arrays.
> Is it possible to do something like
>
> Xcell = {

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com