0
$\begingroup$

According to the following snippet:

Manipulate[{slide, cases},
 {{cases, "a"}, {"a", "b"}},
 Dynamic@Switch[cases,
   "a", Control[{{slide, 0.5, "Slider a"}, 0, 1}],
   "b", Control[{{slide, 0.1, "Slider b"}, 0, 1}]
   ]]

enter image description here

The value of slide is initialized to 0.1, and not 0.5 when, by default, the "a" case is selected, how to correct this behavior? In fact, even when "switching" between "a" and "b", it always take the default value of 0.1.

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Nov 5 '16 at 17:05
  • $\begingroup$ Do you expect the value of slide to be reset whenever cases is changed? That is not how the initialization value works. Initialization happens when the Manipulate first starts. $\endgroup$ – Michael E2 Nov 5 '16 at 23:48
0
$\begingroup$

You may use TrackingFunction and Dynamic.

Manipulate[
 {slide, cases},
 {{cases, "a"}, {"a", "b"},
  TrackingFunction -> {None, Automatic, Switch[#, "a", slide = .5, "b", slide = .1] &}},
 {{slide, 0.5, Dynamic@StringJoin["Slider ", cases]}, 0, 1}
 ]

The TrackingFunction on cases resets the value of slide when cases is updated. The Dynamic on the slide label means that it will always show the current value of cases.

Hope this helps.

$\endgroup$
  • $\begingroup$ Perfect, this is what I was looking for, I think nesting Manipulates is inelegant, and perhaps also difficult to read. $\endgroup$ – Jerome Ibanes Nov 6 '16 at 2:34
0
$\begingroup$

One way to accomplish having the slider be dependent upon the position of the setter bar cases is to use nested Manipulates.

Manipulate[
 With[
  {
   controls = Switch[
     cases,
     "a",
     Control[{{slide, 0.5, "Slider a"}, 0, 1}],
     "b",
     Control[{{slide, 0.1, "Slider b"}, 0, 1}]
     ]
   },

   Manipulate[
   {slide, cases},
   controls]
  ], 

 {{cases, "a"}, {"a", "b"}}
 ]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.