MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Default Value for SetterBar

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113758] Re: Default Value for SetterBar
  • From: Walking Randomly <michael.p.croucher at googlemail.com>
  • Date: Wed, 10 Nov 2010 06:31:08 -0500 (EST)
  • References: <ibb25g$54a$1@smc.vnet.net>

On Nov 9, 8:53 am, Gregory Lypny <gregory.ly... at videotron.ca> wrote:
> Hello everyone,
>
> I have a default value for a variable, x, in a Manipulate.  It uses a s=
etter bar.
>
>         {x, .35, "My Variable"}, Range[.2, .5, .05], ControlType =
-> SetterBar}
>
> But unlike a slider whose thumb position moves to the default value when =
the Manipulate is first opened, the default value on the setter bar is not =
highlighted.  How can I get it to highlight so that users know where they=
 are starting?
>
> Regards,
>
> Gregory

This was a fun one :)

If you do

Manipulate[x,
 {{x, 2, "My Variable"}, Range[1, 5, 1], ControlType -> SetterBar,
  ControlType -> SetterBar}
 ]

Then the default value (2 in this case) IS highlighted but, as you
point out, if you do

Manipulate[x,
 {{x, 0.35, "My Variable"}, Range[0.2, 0.5, 0.05],
  ControlType -> SetterBar, ControlType -> SetterBar}
 ]

Then 0.35 isn't highlighted.  So, what's going on??  The clue comes if
you do

In[8]:= Range[.2, .5, .05] // InputForm

{0.2, 0.25, 0.30000000000000004, 0.35000000000000003, 0.4,
0.45, 0.5}

You see that tiny little floating point error?....
0.35000000000000003?  THAT's the value that the button takes.  So,
technically speaking 0.35 isn't on ANY of the buttons and so it isn't
highlighted.
Try this

Manipulate[x,
 {{x, 0.35, "My Variable"}, N[Range[2/10, 5/10, 1/20]],
  ControlType -> SetterBar, ControlType -> SetterBar}
 ]

Cheers,
Mike
www.walkingrandomly.com


  • Prev by Date: Re: DownValues
  • Next by Date: Re: issue with LinearSolve[] when using SparseArray
  • Previous by thread: Re: Default Value for SetterBar
  • Next by thread: Fonts in Demonstrations and Player Notebooks