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$ Commented Dec 5, 2014 at 16:21
  • $\begingroup$ Removing the semicolon still gave me an error... $\endgroup$ Commented 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$ Commented 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$ Commented Dec 5, 2014 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.