Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg103780] Re: How to find which variable caused the trigger in Manipulate[]
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Mon, 5 Oct 2009 13:18:04 -0400 (EDT)
  • References: <hacmmv$sju$1@smc.vnet.net>

Nasser Abbasi wrote:
> 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.

Do you think a manipulate with 10 plots is a good idea after all? If
these are supposed to fit on one screen they are probably small, and
then is there really any value in seeing them all at once? Just
wondering, since I haven't yet met a situation where that would have
made much sense...

> 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.

Have you looked at the section: 'Using Dynamic inside Manipulate'
within: 'tutorial/AdvancedManipulateFunctionality' ?

I think it does explain exactly what you need. You just need to
understand that the logic is the other way around: Dynamic will (usually
automatically) just update those plots which depend on the value you
just changed. This does work as you probably want:

Manipulate[Grid[{{
    Dynamic[Plot[Sin[a*x], {x, -Pi, Pi}, PlotLabel -> RandomReal[]]],
    Dynamic[Plot[Sin[b*x], {x, -Pi, Pi}, PlotLabel -> RandomReal[]]]
    }}], {a, 0, 1}, {b, 0, 1}]

I have put some random labels so that you can see that indeed only one
of the plots is regenerated when using one of the sliders...

hth,

albert


  • Prev by Date: Re: What Mathematica "says" on two BBP type infinite sums
  • Next by Date: Re: generating submultisets with repeated elements
  • Previous by thread: Re: Colorfunction + parametricplot3d + plotrange = ?
  • Next by thread: Re: How to find which variable caused the trigger in Manipulate[]