MathGroup Archive 2008

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

Search the Archive

Selecting dynamically from a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84691] Selecting dynamically from a list
  • From: John Jowett <John.M.Jowett at gmail.com>
  • Date: Thu, 10 Jan 2008 02:24:44 -0500 (EST)

Hello,
       While writing this post, I found the solution myself.  At the
risk of making myself look a bit slow, let me communicate it anyway.
Conceivably it may help someone else who doesn't find the solution
obvious.

I have an application where, in essence, I would like to visually pick
a few values out of a list to make a new list.  I can do it at a basic
level with

mylist = {a, b, c, d, e, f};

CheckboxBar[Dynamic[mychoice0], mylist]

which displays a row of check boxes.  After picking a couple I find
that the variable mychoice0 has simply been assigned a value {a,c,e},
for example.  I can then go on and calculate other things with it,
e.g.,

Length[mychoice0]   which returns 2.

So far, so good.  Then I try to build on that, by writing a function
to pick from an arbitrary list.  After some trial and error, I came up
with


choosein[myl_List] := Module[{mychoice1 = {}},
  Print[CheckboxBar[Dynamic@mychoice1, myl]];
  Dynamic[mychoice1]]

and try it out with

myc = choosein[mylist]

Sure enough this displays an output corresponding to my choice from
the check boxes.   However if I try to do anything else with the
variable myc, I quickly find out that it is not what it appears to be
and cannot be used in calculations.  This was puzzling until I
discovered that

myc1 = Setting[myc]

will give the list I wanted.  However it is NOT possible to
incorporate the call to Setting in the definition of the function
choosein.

Can anyone improve on this approach ?

John Jowett



  • Prev by Date: Re: How to ParametricPlot3D a plane given Normal and Distance
  • Next by Date: Re: BarChart Question
  • Previous by thread: ListContourPlot and InterpolationOrder
  • Next by thread: Re: Selecting dynamically from a list