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: [mg105531] Re: variable number of controls in manipulate
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 7 Dec 2009 01:59:31 -0500 (EST)
  • Reply-to: hanlonr at cox.net

Perhaps this will help.

vartitles = {
   "Emissions",
   "Weathering scheme",
   "Ca weath feedback",
   "Si weath feedback"};

varvalues = {
   {"None", "1000GtC", "3000GtC", "5000GtC"},
   {"Globavg", "GKWM", "GEM_CO2"},
   {"On", "Off"},
   {"On", "Off"}};

Module[{n = 1},
 Manipulate[
  Evaluate[
   Table[v[n], {n, Length[varvalues]}]],
  Evaluate[
   Sequence @@ (
     Inner[{{v[n++], #2[[1]], #1}, #2} &,
      vartitles, varvalues, List])]]]

Although I recommend that you enter and store the titles and values together to keep them linked. For example,

varData = {
   {"Emissions", 
    {"None", "1000GtC", "3000GtC", "5000GtC"}}, 
   {"Weathering scheme", 
    {"Globavg", "GKWM", "GEM_CO2"}}, 
   {"Ca weath feedback", 
    {"On", "Off"}}, 
     {"Si weath feedback", 
    {"On", "Off"}}};

Module[{n = 1},
 Manipulate[
  Evaluate[
   Table[v[n], {n, Length[varvalues]}]],
  Evaluate[
   Sequence @@ (
     Inner[{{v[n++], #2[[1]], #1}, #2} &,
      Sequence @@
       Transpose[varData], List])]]]


Bob Hanlon

---- Greg Colbourn <gcolbourn at hotmail.com> 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



  • Prev by Date: Washington DC Area Mathematica Special Interest Group
  • Next by Date: Invitation Letter for IMS2010,July 16-18th, 2010, Beijing, China
  • Previous by thread: variable number of controls in manipulate
  • Next by thread: Re: Re: variable number of controls in manipulate