Message Boards Message Boards

0
|
5114 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Resetting Slider Values with PaneSelector?

Posted 10 years ago

Hi all:

I'm having the following problem. I would like to design a demonstration that uses different ranges of a variable depending on which button is pushed, for example:

Manipulate[
 a,
 {{b, 1}, {1, 2}},
 PaneSelector[{
   1 -> Control[{{a, -3}, -4, 1}],
   2 -> Control[{{a, 4}, 1, 5}]},
  Dynamic[b]
  ]
 ]

Here, the values for A depend on the choice for B. However, when changing from one b value to the other, the "initial value" for A doesn't reset, despite the fact that an initial value is assigned.

The only workaround I've found that seems to produce the effect I'm looking for is to do this:

Manipulate[
 Which[b == 1, a, b == 2, [Alpha]],
 {{b, 1}, {1, 2}},
 PaneSelector[{
   1 -> Control[{{a, -3}, -4, 1}],
   2 -> Control[{{[Alpha], 4}, 1, 5}]},
  Dynamic[b]
  ]
 ]

However, this gets very tedious with more sophisticated uses for A and alpha.

Anyone have a suggestion?

Thanks for the help!

Rob

POSTED BY: Rob Holman

Perhaps a variation on this hack may work for you:

cntl[range : {l_, u_}] := Control[{{a, Mean[range]}, l, u}]

With[{ranges = {{-4, 1}, {1, 5}}},
 Manipulate[a = Clip[a, ranges[[b]]], {{b, 1}, {1, 2}},
  PaneSelector[
   MapIndexed[(#2[[1]] -> cntl[#1] ) &, ranges],
   Dynamic[b]]
  ]
 ]

However, the a=Clip[a] probably causes some unwanted firing of the Dynamic object from Manipulate. There is likely a better way.

POSTED BY: W. Craig Carter
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract