MathGroup Archive 2009

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103753] How to find which variable caused the trigger in Manipulate[] ?
  • From: "Nasser Abbasi" <nma at 12000.org>
  • Date: Mon, 5 Oct 2009 07:36:57 -0400 (EDT)
  • Reply-to: "Nasser Abbasi" <nma at 12000.org>

Hello,

Version 7.

Manipulate[] works by evaluating an expression each time any one of its 
control variables has changed.

I have an example, where the expression involves 2 plots and 2 control 
variables, like this:

Manipulate[

Grid[{
    {Plot[Sin[a*x], {x, -Pi, Pi}],
     Plot[Sin[b*x], {x, -Pi, Pi}]}}
  ],

 {a, 0, 1}, {b, 0, 1},
  TrackedSymbols -> {a, b}
]

So, in the above, each time 'a' or 'b' is changed, BOTH plots are called 
since they are ofcourse part of the expression, even though only one of them 
will actually change from earlier time. This can be waste of time.

I'd like to ask Mathematica to tell me which variable trigged the 
revaluation of the Manipulate expression.

i.e., I really would like to do _something_ like the following. First 
suppose there is a function way W[] which returns the name of the variable 
which caused the trigger, then I'd write

Which[ W[] == "a", Plot[Sin[a*x], {x, -Pi, Pi}],
            W[] == "b", Plot[Sin[b*x], {x, -Pi, Pi}]
]

The reason I am asking, is that I have a manipulate with 10 plots all on one 
display, and I do not want to plot each of them each time when only one plot 
is actually changing.

Currently I solve this problem by having a RadioButton[] next to each plot. 
When the radioButton[] is clicked, then I check which RadioButton is TRUE 
out of the 10 radioButtons, then this tells me which plot needs to be 
replotted.

If I can find which variable did the triggering, I can get rid of the radio 
buttons and simplify the interface.

Thank you,
--Nasser
ps. I did read the docs from the documentation center on dynamics and 
Manipulate (they are good), but do not see the solution there.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4479 (20091004) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





  • Prev by Date: Re: confused about == vs === in this equality
  • Next by Date: Re: confused about == vs === in this equality
  • Previous by thread: Re: Paper heading: does not work?
  • Next by thread: Which is better, foo[n_Integer] or foo[n_?IntegerQ] ?