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