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: [mg103798] Re: How to find which variable caused the trigger in Manipulate[]
  • From: "Nasser Abbasi" <nma at 12000.org>
  • Date: Tue, 6 Oct 2009 08:02:27 -0400 (EDT)
  • References: <hacmmv$sju$1@smc.vnet.net> <had9pe$ad6$1@smc.vnet.net>

"Albert Retey" <awnl at gmx-topmail.de> wrote in message 
news:had9pe$ad6$1 at 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.
>> 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


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

Your example was useful to help me learn something, but my specifications 
were not clear, so I am still looking for a solution.

Let me be more clear what I want.

I want to perform one operation, which will end up generating ONE plot. But 
this operation will behave differently depending on which control variable 
has changed.

So, in your example, 2 plots are generated, but only one changes depending 
on which variable changed.

I really want ONE plot, but the content of this one plot will be determined 
by which control variable changed.

So, I really still think there is a need to find WHICH control variable 
triggered the revaluation of Manipulate[].

I tried few hacks by having global variables to save the old value of the 
control variable, then check if the current control variable value is the 
same as the old one or not, and based on this generate the appropriate plot, 
but nothing seems to work for me. Too may Dynamic[]'s, and I also do not 
know where to save these global variables since a demo requires having only 
a Manipulate[] section and nothing else.

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}]])
]


So, I am back to the drawing board. It seems to me this is something that 
should not be hard to do, but I've been struggling with this for 2 days.  In 
other systems, I could code a call back routine to tell me which event 
occurred on the GUI, but with Manipulate[] this feature seems to be missing?

Again, any ideas are appreciated.

thank you,
--Nasser 



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4482 (20091005) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




  • Prev by Date: Re: How to find which variable caused the trigger in Manipulate[]
  • Next by Date: Re: Re: generating submultisets with repeated
  • 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[]