Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: dynamic variable definiton

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67269] Re: dynamic variable definiton
  • From: albert <awnl at arcor.de>
  • Date: Thu, 15 Jun 2006 03:25:45 -0400 (EDT)
  • References: <e6opcl$s4p$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

T.Sariyski wrote:

> Hi,
> I have a list of lists. The first element of each list is a description,
> the rest are numerical. Is it possible dynamic to create variable and to
> assign values to them? For example, I read data with ReadList:

yes, look into ToExpression

>
rawdata=ReadList["myfile.txt",Word,WordSeparators->"",RecordListsï?¢True,RecordSeparatorsï?¢{"\n\n","\n","\n"}];
> 

I'm not sure, but I think you want the WordSeparators to be a space, not an
empty string???

> {{Face 1},{observ 0.1000E+02 0.3000E+01 0.4000E+01},{center 0.1050E+02
> 0.3000E+01 0.4000E+01},{e1 0.1000E+01 0.0000E+00 0.0000E+00},{e2
> 0.0000E+00 0.1000E+01 0.0000E+00},{e3 0.0000E+00 0.0000E+00
> 0.1000E+01},{v1 0.1050E+02 0.3500E+01 0.4500E+01},{v2 0.1050E+02
> 0.2500E+01 0.4500E+01},{v3 0.1050E+02 0.2500E+01 0.4000E+01},{v4
> 0.1050E+02 0.3500E+01 0.4000E+01}}
> 
> I would like to have:
> 
> Face=1;
> obsrv={0.1000E+02 , 0.3000E+01, 0.4000E+01};
> center={0.1050E+02, 0.3000E+01, 0.4000E+01};
> e1=... etc.

your output looks like every line is just a string, so you might needs some
string-processing before executing ToExpression. If you manage to get
somehing like:
line = {"obsrv","0.1000E+02","0.3000E+01","0.4000E+01"}

using:

ToExpression/@line
With[{varname=line[[1]]},varname=Rest[line]]

will do what you want. make sure that there are no definitions for any of
the "descriptions", otherwise you might see error messages...

hth

albert


  • Prev by Date: Re: linux front end tutorial
  • Next by Date: Re: dynamic variable definiton
  • Previous by thread: dynamic variable definiton
  • Next by thread: Re: dynamic variable definiton