0
$\begingroup$

I am trying to adjust the start and end points of a Manipulate function using variables that only change value if a certain condition is met. What is wrong with the code below?

ClearAll["Global`*"];

Manipulate[

 If[True, xinit = 3; xMax = 5;

  , xinit=1; xMax=4;];

 x,

 {{x, xinit}, 1, xMax, 1}

 ]
$\endgroup$
3
  • $\begingroup$ remove semicolon after xMax = 5 $\endgroup$
    – funnyp0ny
    Dec 5, 2014 at 16:21
  • $\begingroup$ Removing the semicolon still gave me an error... $\endgroup$
    – Aaron
    Dec 5, 2014 at 16:25
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 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. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – user9660
    Dec 5, 2014 at 16:33

1 Answer 1

2
$\begingroup$

Here's one way: make the range be a checkbox (to choose the desired range for the x variable). Also, place the xinit and xmax variables inside Dynamic so they react to the changed values.

Manipulate[If[range, xinit = 3; xMax = 5;, xinit = 1; xMax = 4;]; x, 
  {{x, Dynamic[xinit]}, 1, Dynamic[xMax], 1}, {range, {False, True}}]
$\endgroup$
1
  • $\begingroup$ YES making the parameter Dynamic[] is exactly what I needed!! Thanks so much! $\endgroup$
    – Aaron
    Dec 5, 2014 at 20:34

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.