MathGroup Archive 2009

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

Search the Archive

Re: How to find which variable caused the trigger in Manipulate[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103788] Re: How to find which variable caused the trigger in Manipulate[]
  • From: "Nasser Abbasi" <nma at 12000.org>
  • Date: Tue, 6 Oct 2009 08:00:31 -0400 (EDT)

"Nasser Abbasi" <nma at 12000.org> wrote in message news:...

>
> Again, I want something like this
>
> Manipulate[
> process[( pickTheCorrectControlVariableWhichChanged ],
> {a, 0, 1}, {b, 0, 1}, Initialization :>
>
>   (process[arg_] := Module[{}, Plot[Sin[arg*x], {x, -Pi, Pi}]])
> ]
>
>

I made some progress and I think I have a solution.

I save the old value of each control variable in a global variable, then in 
the Manipulate expression, I check, using an If statement which current 
value of the control variable is different from the old value. I got it to 
work ok finally.

Here is an example:

olda = 999;
oldb = 999;

Manipulate[
   If[olda != a, {olda = a; Style[StringJoin["a=", ToString[a]]]},

   If[oldb != b, {oldb = b; Style[StringJoin["b=", ToString[b]]]},

    Text["this message should NOT show up!"]]], {a, 0, 1}, {b, 0, 1},

  LocalizeVariables -> True, TrackedSymbols -> {a, b}]


Here is another example as the above, but with plot

olda = 999;
oldb = 999;

Manipulate[
   If[olda != a, {olda = a; Plot[Sin[a*x], {x, -Pi, Pi}, PlotLabel -> "a"]},

   If[oldb != b, {oldb = b; Plot[Sin[b*x], {x, -Pi, Pi}, PlotLabel -> "b"]},

    Text["this message should NOT show up!"]]], {a, 0, 1}, {b, 0, 1},

  LocalizeVariables -> True, TrackedSymbols -> {a, b}, ContinuousAction -> 
False]

So, the above seems to do what I want.  i.e. a way to find which control 
variable changed.

The problem is where to save these olda and oldb global variables as I am 
writing this for a demo.

I could ofcourse have a Module around the whole thing as follows and have 
olda and olodb as local variables to the module

Module[{oldb = 999, olda = 999},

  Manipulate[If[olda != a, {olda = a; Plot[Sin[a*x], {x, -Pi, Pi}, 
PlotLabel -> "a"]},
    If[oldb != b, {oldb = b; Plot[Sin[b*x], {x, -Pi, Pi}, PlotLabel -> 
"b"]},
     Text["this message should NOT show up!"]]], {a, 0, 1}, {b, 0, 1},
   LocalizeVariables -> True, TrackedSymbols -> {a, b}, ContinuousAction -> 
False
  ]

]

But I am not sure if this is allowed in a demonstration. I need to check. If 
so, then my problem is finally solved

--Nasser




  • Prev by Date: Re: generating submultisets with repeated elements
  • Next by Date: Re: Colorfunction + parametricplot3d + plotrange = ?
  • Previous by thread: Re: How to find which variable caused the trigger in Manipulate[]
  • Next by thread: Re: How to find which variable caused the trigger in Manipulate[]