MathGroup Archive 2005

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

Search the Archive

Re: Can't assign value to symbols

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58435] Re: [mg58409] Can't assign value to symbols
  • From: János <janos.lobb at yale.edu>
  • Date: Sat, 2 Jul 2005 04:06:49 -0400 (EDT)
  • References: <200507010602.CAA09182@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Jul 1, 2005, at 2:02 AM, Lee Newman wrote:

> Hello,
>
> Situation:  I have a table that contains parameters and sets of values
> that I want to assign to the parameters for the purposes of running a
> simulation.
> - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}}
> - want to assign values in a given row to the symbols listed in the
> first row.
> - tried using:  MapThread[  #1 = #2 &, {parameters[[1]], parameters 
> [[3]]} ]
> - fails with error  "Tag Slot in #1 is Protected"
> - tried adding Unprotect[#1] and a variety of other attemps, but can't
> get it to work.
>
> Anyone know how might accomplish this?
>
> Thanks,
> Lee
>
>

One possibility:

In[1]:=
parameters = {{a, b, c},
    {1, 2, 3}, {4, 5, 6},
    {7, 8, 9}}
Out[1]=
{{a, b, c}, {1, 2, 3},
   {4, 5, 6}, {7, 8, 9}}

In[2]:=
assignments = MapThread[
    StringJoin[ToString[#1],
      "=", ToString[#2]] & ,
    Most[Most[parameters]]]
Out[2]=
{"a=1", "b=2", "c=3"}

In[15]:=
ToExpression[assignments]
Out[15]=
{1, 2, 3}

In[20]:=
a
Out[20]=
1


János


  • Prev by Date: Re: a question about the UnitStep function
  • Next by Date: how to find n in expression x^n using a pattern?
  • Previous by thread: Can't assign value to symbols
  • Next by thread: Re: Can't assign value to symbols