MathGroup Archive 2007

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

Search the Archive

associate a parameter name with a string

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75395] associate a parameter name with a string
  • From: luhao <luhaorice at gmail.com>
  • Date: Sat, 28 Apr 2007 05:55:53 -0400 (EDT)

Dear all,
I have groups of files and I'd like to call a function with each file and assign the result
to a parameter with similar name as the file.  How can I do that?

Here are what I tried.

In[30]:=
Map[ToExpression[StringReplace[#,"_26.txt"->"phe"]]&,FileNames["fd*26.txt"]]
Out[30]=
{fd01001phe,fd01002phe,fd01003phe,fd01004phe,fd01005phe,fd01phe} 

In[31]:=
FileNames["fd*26.txt"]
Out[31]=
{fd01001_26.txt,fd01002_26.txt,fd01003_26.txt,fd01004_26.txt,fd01005_26.txt,\
fd01_26.txt}

In[32]:=
MapThread[#1=f[#2]&,{%30,%31}]
 Set::write : Tag Slot in #1 is Protected.
Out[32]=
{f[fd01001_26.txt],f[fd01002_26.txt],f[fd01003_26.txt],f[fd01004_26.txt],
  f[fd01005_26.txt],f[fd01_26.txt]}

Any suggestions?

Thanks,
Hao


  • Prev by Date: Re: ordering a large matrix and referring to the named rows later
  • Next by Date: Finding cardinality of set based on random selection from set
  • Previous by thread: Re: Re: Suppress Arrowheads (Combinatorica)
  • Next by thread: Re: associate a parameter name with a string