MathGroup Archive 2009

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

Search the Archive

Re: Manipulate: How to correctly adjust one control parameters based on current setting of another control?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103063] Re: [mg103049] Manipulate: How to correctly adjust one control parameters based on current setting of another control?
  • From: "Nasser Abbasi" <nma at 12000.org>
  • Date: Sun, 6 Sep 2009 07:38:19 -0400 (EDT)
  • References: <5118287.1252145556385.JavaMail.root@n11> <000001ca2e39$4af95bf0$e0ec13d0$@net>
  • Reply-to: "Nasser Abbasi" <nma at 12000.org>

(sorry for top posting)

Thank you David for your solution below using custom Dynamics.

However, I am writing something with the hope to have it as a demonstration 
for the Wolfram demo site, and I do not think one is allowed to use Dynamics 
directly in those, one must use Manipulate[], an engineer from Wolfram once 
told me that I remember, and here is the guidelines page:

http://demonstrations.wolfram.com/guidelines.html

"Nested Manipulates or functions that return Manipulate are not allowed. 
Keep things simple and use only one Manipulate command per Demonstration."

Someone can correct me if I am wrong.

Is there a way to solve this while still using Manipulate[]? I can still use 
Dynamic[], but the whole thing must be wrapped inside one Manipulate[] 
command.

Thank you,
--Nasser

----- Original Message ----- 
From: "David Park" <djmpark at comcast.net>
To: "'Nasser Abbasi'" <nma at 12000.org>; <mathgroup at smc.vnet.net>
Sent: Saturday, September 05, 2009 9:58 AM
Subject: [mg103063] RE: [mg103049] Manipulate: How to correctly adjust one control 
parameters based on current setting of another control?


> In the long run it is usually easier to write a custom dynamic. It's worth
> learning how to do it because one can spend a lot of time figuring out how
> to screw Manipulate into the form one wants, which is sometimes possible 
> and
> sometimes not.
>
> The trick for custom dynamics is to divide your variables into primary
> dynamic variables and dependent variables. Write a routine to calculate 
> the
> dependent variables from the primary variables. Use the two-argument form 
> of
> Dynamic to call the routine when a primary variable is changed. So in the
> following: choice is a primary dynamic variable, xmin and xmax are 
> dependent
> variables and calcSliderValues is the routine to calculate them and set 
> the
> initial value for x.
>
> DynamicModule[
> {(* Primary dynamic variables *)
>  choice = 1, x,
>  (* Dependent dynamic variables *)
>  xmin, xmax, calcSliderValues},
>
> (* Routine to calculate dependent variables *)
> calcSliderValues[c_] :=
>  If[c == 1,
>   xmin = 1; x = 1; xmax = 10,
>   xmin = 0; x = 1; xmax = 20];
> calcSliderValues[choice];
>
> Panel[
>  Column[{
>    Row[{"setter choice ",
>      SetterBar[
>       Dynamic[choice, (choice = #;
>          calcSliderValues[choice]) &], {1 -> "UP", -1 -> "DOWN"}]}](*
>    Setter Row *),
>    Dynamic@Row[{"x = ", Slider[Dynamic[x], {xmin, xmax}]}] (*
>    Slider Row *),
>    Dynamic[x]
>    }] (* Display Column *),
>  BaseStyle -> {FontSize -> 16}
>  ](* Panel *)
> ]
>
>
> David Park
> djmpark at comcast.net
> http://home.comcast.net/~djmpark/
>
>
> From: Nasser Abbasi [mailto:nma at 12000.org]
>
> Hello.
>
> This is Mathematica 7.
>
> I have Manipulate control (a slider) which I want to dynamically adjust 
> its
> initial value and maximum value based on what one selects as a choice from
> another control (SetterBar) and also change the position of the slider 
> (i.e.
>
> the current value of the slider) based on the choice selected.
>
> The following code below seems to work initially. Using 'If' statement, I
> check the current choice, and set the initial and maximum value of the
> slider.
>
> The problem though is that the current value of the slider (i.e. the 
> current
>
> position of the slider) remains at whatever value it was before the user
> changed the choice, and this could result in the current value of the 
> slider
>
> being larger than the maximum being set for the new choice.
>
> What I want is the following: When the user selects a new choice (from the
> SetterBar), I want to reset the current position on the slider as well the
> initial and the maximum value.
>
> Here is the code to help explain:
>
> Manipulate[Text[x],
>
>  {{x, 1, "x="}, If[choice == 1, 0, 1],    If[choice == 1, 10, 20], 0.1},
>
>  {{choice, 1, "select choice"},  {1 -> "UP", -1 -> "DOWN"}, ControlType ->
> SetterBar}
>
> ]
>
> So, when one selects UP, I change the initial slider value to start at 1
> instead of at 0, and made the maximum slider to be 10 instead of 20.
> However, the value of 'x' itself could be at say 12 at this time (becuase
> the user was moving it), and so it overflows now.
>
> How can I also update 'x' to start at some specific value each time the 
> user
>
> changes the choice from UP to DOWN or from DOWN to UP?  Putting another If
> statement does NOT work:
>
> Manipulate[Text[x],
>
> {{x, If[choice == 1, 3, 5], "x="},   If[choice == 1, 0, 1], If[choice == 
> 1,
>
> 10, 20], 0.1},
>
>  {{choice, 1, "select choice"}, {1 -> "UP", -1 -> "DOWN"},
>   ControlType -> SetterBar}
>
> ]
>
> I know I need to use Dynamic[] somewhere, but I not sure where and how to
> force current slider value to rest each time the setterbar is clicked. I
> need some sort of action associated with SetterBar which I can use each 
> time
>
> its value changes, but SetterBar has no such option.
>
> any help is appreciated.
>
> --Nasser
>
>
>
>
>
> __________ NOD32 4398 (20090905) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
> 



  • Prev by Date: Re: Manipulate: How to correctly adjust one control parameters based on current setting of another control?
  • Next by Date: Ukkonen's Suffix Tree Algorithm in Mathematica
  • Previous by thread: Re: Manipulate: How to correctly adjust one control parameters based on current setting of another control?
  • Next by thread: Inputting Dynamic Variables