I want to use a pair of sliders to set integer values for two variables nLo and nHi, each of which can individually range from 1 to 100, but subject to the restriction that nHi >= nLo. So I set up a slider for each variable that has a range that depends dynamically on the other variable:
nLo = 1; nHi = 100;
Column[
{
Labeled[Slider[Dynamic[nLo], {1, Dynamic[nHi], 1},
Appearance -> "Labeled"], "nLo", Left
],
Labeled[Slider[Dynamic[nHi], {Dynamic[nLo], 100, 1},
Appearance -> "Labeled"], "nHi", Left
],
Dynamic[{nLo, nHi}]
}
]
The problem is that as soon as I adjust nHi, its value becomes real (displays with a decimal point) rather than integer. I presume that this is because the slider for nHi can't tell that its first range argument Dynamic[nLo] is actually an integer and so it defaults to real values instead. Any suggestions as to how to force nHi to remain integer valued? (Linux Mathematica v8.0.1)
Alternatively you could do something like
nLo = 1; nHi = 100;
Column[{Labeled[
Slider[Dynamic[nLo], {1, Dynamic[nHi], 1},
Appearance -> "Labeled"], "nLo", Left],
Labeled[Slider[
Dynamic[nHi, (nHi = Round[#]) &], {Dynamic[nLo], 100, 1},
Appearance -> "Labeled"], "nHi", Left],
{Dynamic[nLo], Dynamic[nHi]}}]
Either I fail to understand the requirements of the solution, or this code may only function correctly in Mathematica 7.
Interesting problem. This appears to work:
nLo = 1; nHi = 100;
Column[{Labeled[
Slider[Dynamic[nLo], {1, Dynamic[nHi], 1},
Appearance -> "Labeled"], "nLo", Left],
Labeled[Slider[
Dynamic[nHi], {Dynamic[Unevaluated@Round@nLo], 100, 1},
Appearance -> "Labeled"], "nHi", Left],
Dynamic[{nLo, nHi}]}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With