10
$\begingroup$

I modified an example from the documentation to have a RadioButton control over a specific list of values:

Manipulate[Plot[Sin[a x + b], {x, 0, 6}], {{a, 2, "Multiplier"}, {1, 2}}, {{b, 
   3, "Phase Parameter"}, {3, 4, 5}}, ControlType -> RadioButton]

Mathematica graphics

However, in place of 1, 2, 3, etc. I'd like textual labels (but still need to pass those specific, discrete numeric values to the object inside the Manipulate).

In the spirit of the Multiplier textual label, I tried

Manipulate[Plot[Sin[a x + b], {x, 0, 6}], 
  {{a, 2, "Multiplier"}, {{1, "cat"}, {2, "dog"}}}, 
  {{b, 3, "Phase Parameter"}, {3, 4, 5}}, ControlType -> RadioButton]

to no avail:

Mathematica graphics

How do I get the appearance (and behavior) here that I am after?

$\endgroup$

2 Answers 2

11
$\begingroup$

You can use RadioButtonBar which allows labeling of the values:

Manipulate[Plot[Sin[a x + b], {x, 0, 6}], 
 {{a, 1, "Multiplier"}, {1 -> "cat",  2 -> "dog"}}, 
 {{b, 3, "Phase Parameter"}, {3, 4, 5}},  ControlType -> RadioButtonBar]

enter image description here

or

 Manipulate[Plot[Sin[a x + b] /. {"cat" -> 1, "dog" -> 2}, {x, 0, 6}], 
  {{a,  "cat", "Multiplier"}, {"cat", "dog"}}, 
   {{b, 3, "Phase Parameter"}, {3, 4, 5}}, ControlType -> RadioButton]
$\endgroup$
0
2
$\begingroup$
Manipulate[
 Plot[c*Sin[a x + b], {x, 0, 6}], {{a, 1, "Multiplier"}, {1 -> "cat", 
   2 -> "dog"}, RadioButton}, {{b, 3, "Phase Parameter"}, {3, 4, 5}, 
  RadioButton}, {{c, 1, "Peak Amplitude"}, InputField}]

I like using this setup allowing for a variety of Manipulate controls.

$\endgroup$
2
  • $\begingroup$ Does this work for Mma8? $\endgroup$
    – Stefan
    Jul 9, 2013 at 19:44
  • $\begingroup$ I'm running the code in Mathematica 8 and it works. $\endgroup$
    – twhoward99
    Jul 9, 2013 at 20:39

Your Answer

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

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