MathGroup Archive 2009

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

Search the Archive

Re: Manipulate: How to correctly adjust one control parameters based

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103131] Re: Manipulate: How to correctly adjust one control parameters based
  • From: Januk <ggroup at sarj.ca>
  • Date: Wed, 9 Sep 2009 04:41:06 -0400 (EDT)
  • References: <h7tbgd$fue$1@smc.vnet.net>

One option is to do your checks in the body of the Manipulate.  For
example, an extremely simplistic approach can be:

Manipulate[
 If[choice == 1,
  If[x > 10, x = 10];
  If[x < 0, x = 0]
  ];
 If[choice == -1,
  If[x > 20, x = 20];
  If[x < 1, x = 1]
  ];

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

I hope that helps,
Januk


On Sep 5, 5:37 am, "Nasser Abbasi" <n... at 12000.org> wrote:
> Hello.
>
> This is Mathematica 7.
>
> I have Manipulate control (a slider) which I want to dynamically adjust i=
ts
> initial value and maximum value based on what one selects as a choice fro=
m
> 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 curr=
ent
> 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 sli=
der
> 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 th=
e
> SetterBar), I want to reset the current position on the slider as well th=
e
> 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"}, ControlT=
ype ->
> 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 u=
ser
> 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 t=
ime
> its value changes, but SetterBar has no such option.
>
> any help is appreciated.
>
> --Nasser



  • Prev by Date: Efficient way to read binary data line-by-line
  • Next by Date: Re: Re: how to solve the integer equation Abs[3^x-2^y]=1
  • Previous by thread: Re: Efficient way to read binary data line-by-line
  • Next by thread: Background image sizing