MathGroup Archive 2009

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

Search the Archive

Re: variable number of controls in manipulate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105590] Re: variable number of controls in manipulate
  • From: dh <dh at metrohm.com>
  • Date: Thu, 10 Dec 2009 04:57:12 -0500 (EST)
  • References: <hffjje$6s2$1@smc.vnet.net> <4B1F75D6.2080003@metrohm.com> <BLU0-SMTP71F163BD113CE19DA9E23DAC8E0@phx.gbl>

Hi Greg,
if you use the prefix form of a function you must take care of the 
precedence. If you are not sure, use the infix notation:

Manipulate[
    Evaluate[(k =
       Total[(Table[list[[i]], {i, nvar}] - 1)*varmultipliers] + 1);
     k], ##] &@(Sequence @@
    Table[{{list[[i]], 1, vartitles[[i]]},
      Table[j -> varvalues[[i, j]], {j, nvars[[i]]}]}, {i, nvar}])

Daniel

Greg Colbourn wrote:
> Hi Daniel, 
> 
> That works, but I still can't use k for anything else after it's assignment:
> 
> (*edit these to contain more or less variables,with more or less values 
> for \
> each variable:*)
> 
> vartitles = {"emissions", "Weathering scheme", "Ca weath feedbcak",
>    "Si weath feedback"};
> varvalues = {{"none", "1000GtC", "3000GtC", "5000GtC"}, {"Globavg", "GKWM",
>     "GEM_CO2"}, {"on", "off"}, {"on", "off"}};
> nvars = Table[Length[varvalues[[i]]], {i, Length[varvalues]}];
> nvar = Length[nvars];
> Format[v[n_Integer]] := "v" <> ToString[n];
> list = Array[v, nvar];
> varmultipliers =
>   Append[Reverse[
>     Table[Product[nvars[[n]], {n, nvar, nvar - m, -1}], {m, 0, nvar - 
> 2}]], 1];
> (*this generates ensemble number corresponding to variable selection:*)
> 
> Manipulate[(*k=*)
>    Evaluate@(k = Total[(Table[list[[i]], {i, nvar}] - 1)*varmultipliers] 
> + 1);
>    k, ##] &@(Sequence @@
>    Table[{{list[[i]], 1, vartitles[[i]]},
>      Table[j -> varvalues[[i, j]], {j, nvars[[i]]}]}, {i, nvar}])
> 
> doesn't work. I wan't to use k to pick out parts of an array.
> 
> Cheers,
> Greg
> 
> 
> On 9 Dec 2009, at 10:03, dh wrote:
> 
>> Hi Greg,
>> Evaluate is only activated if it is the argument of a function with 
>> one of the Hold attributes, like e.g. Manipulate[ Evaluate[..],..]. 
>> However, if you say:  Manipulate[k= Evaluate[..],..], then Evaluate is 
>> an argument of Set, not of Manipulate and has no effect.
>> therefore:
>>
>> Manipulate[Evaluate@(k = Total[...
>>
>> Daniel
>>
>>
>> Greg Colbourn wrote:
>>> Hi.
>>> I'm running ensembles of models and want to look at the results in 
>>> Mathematica in an automated way. Part of this revolves around 
>>> automatically generating lists of buttons corresponding to variables 
>>> using Manipulate - the number of variables to loop over is itself 
>>> variable(!).
>>> I can work out automatically a number corresponding to an individual 
>>> ensemble member depending on which variables are chosen:
>>> (* edit these to contain more or less variables, with more or less 
>>> values for \
>>> each variable: *)
>>> vartitles = {"emissions", "Weathering scheme", "Ca weath feedbcak",
>>>   "Si weath feedback"};
>>> varvalues = {{"none", "1000GtC", "3000GtC", "5000GtC"}, {"Globavg", 
>>> "GKWM",
>>>    "GEM_CO2"}, {"on", "off"}, {"on", "off"}};
>>> nvars = Table[Length[varvalues[[i]]], {i, Length[varvalues]}];
>>> nvar = Length[nvars];
>>> Format[v[n_Integer]] := "v" <> ToString[n];
>>> list = Array[v, nvar];
>>> varmultipliers =
>>>  Append[Reverse[
>>>    Table[Product[nvars[[n]], {n, nvar, nvar - m, -1}], {m, 0, nvar - 
>>> 2}]], 1];
>>> (* this generates ensemble number corresponding to variable selection: *)
>>> Manipulate[
>>>   (*k=*)Evaluate[
>>>    Total[(Evaluate[Table[Evaluate[list][[i]], {i, nvar}]] - 1)*
>>>       varmultipliers] + 1],     ##] &@(Sequence @@
>>>   Table[{{list[[i]], 1, vartitles[[i]]},
>>>     Table[j -> varvalues[[i, j]], {j, nvars[[i]]}]}, {i, nvar}])
>>> However, when I want to do anything with this number (removing the 
>>> commented out "k="), it becomes a list of symbols and no longer a 
>>> number, despite me using Evaluate. Ideally, I want to be able to use 
>>> this number (k) as an index to pick out data from arrays.
>>> What do I need to do?
>>> Greg Colbourn
>>
>>
>>
> 


-- 

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh at metrohm.com>
Internet:<http://www.metrohm.com>



  • Prev by Date: Re: variable number of controls in manipulate
  • Next by Date: Re: Re: Special Input Characters' Reference Table
  • Previous by thread: Re: variable number of controls in manipulate
  • Next by thread: Re: SetOptions[Plot,.Z..] vs using Plot[,.Z..] behaves