Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nesting Manipulate to Create a Variable Number of Controls

76 views
Skip to first unread message

Gregory Lypny

unread,
Apr 3, 2014, 2:17:00 AM4/3/14
to
Hello everyone,

I used the example in the Documentation Center to create a Manipulate with a variable number of controls. Here is the example:

Manipulate[
With[{value = Table[c[i], {i, 1, n}],
controls = Sequence @@ Table[{c[i], 0, 1}, {i, 1, n}]},
Manipulate[value, controls]], {n, 1, 10, 1}]

How would I change the code above so that it produces pairs on controls side by side? So if n=3, the control area would look like this.

nameMenu1 valueSlider1
nameMenu2 valueSlider2
nameMenu3 valueSlider3

Any tip would be much appreciated,

Gregory

Bob Hanlon

unread,
Apr 4, 2014, 3:59:09 AM4/4/14
to

If I understand what you want:

Manipulate[
Manipulate[
"test",
Evaluate[Sequence @@ Table[
Row[{
Control[Evaluate[{
{ToExpression[
"nameMenu" <>
StringJoin[ToString /@
IntegerDigits[k, 10, 2]]],
Subsuperscript["name", k, 1]},
Table[
Subsuperscript["name", k, j],
{j, 5}],
ControlType -> PopupMenu}]],
Spacer[25 - 3 Floor[Log10[k]]],
Control[Evaluate[{
{ToExpression[
"valueSlider" <>
StringJoin[ToString /@
IntegerDigits[k, 10, 2]]],
1},
1, 10, 1, Appearance -> "Labeled"}]]}],
{k, n}]]],
{{n, 3, "Number of control pairs"}, Range[10]}]



Bob Hanlon

Gregory Lypny

unread,
Apr 5, 2014, 1:48:00 AM4/5/14
to
Ahhh, good stuff. Although, it seems that the list cannot be named as in

x = Evaluate[Table[ToExpression[ "valueSlider" <> StringJoin[ToString /@ IntegerDigits[k, 10, 2]], {k, n}]]

to be used in other computations. But I'll tinker with it.

Thanks again,

Gregory


On Fri, Apr 4, 2014, at 7:02 PM, Bob Hanlon <hanlo...@gmail.com> wrote:

> Manipulate[
> Manipulate[
> Evaluate[Table[
> ToExpression[
> "valueSlider" <>
> StringJoin[ToString /@
> IntegerDigits[k, 10, 2]]],
> {k, n}]],
> Evaluate[Sequence @@ Table[
> Row[{
> Control[Evaluate[{
> {ToExpression[
> "nameMenu" <>
> StringJoin[ToString /@
> IntegerDigits[k, 10, 2]]],
> Subsuperscript["name", k, 1]},
> Table[
> Subsuperscript["name", k, j],
> {j, 5}],
> ControlType -> PopupMenu}]],
> Spacer[25 - 3 Floor[Log10[k]]],
> Control[Evaluate[{
> {ToExpression[
> "valueSlider" <>
> StringJoin[ToString /@
> IntegerDigits[k, 10, 2]]],
> 1},
> 1, 10, 1, Appearance -> "Labeled"}]]}],
> {k, n}]]],
> {{n, 3, "Number of control pairs"}, Range[10]}]
>
>
> Bob Hanlon
>
>
>
> On Fri, Apr 4, 2014 at 4:49 PM, Gregory Lypny <gregor...@videotron.ca> wrote:
> Works like a charm, but one thing that I struggle with is collecting the values of the variables into one list. For example, of n=4, how = would I create a list of values {valueSlider01, valueSlider02, valueSlider03, valueSlider04}?
>
> I've tried a number of variations using ToExpression and Evaluate but always end up with the literal of valueSlider01. etc.
>
> Gregory

Gregory Lypny

unread,
Apr 5, 2014, 1:48:21 AM4/5/14
to
Hi Bob,

Thanks! Just what the doctor ordered. Good exercise for code study too because I can compare your use of Evaluate with the Documentation Center's use of With.

Thanks once again,

Gregory


On Thu, Apr 3, 2014, at 11:28 PM, Bob Hanlon <hanlo...@gmail.com> wrote:

> If I understand what you want:
>
> Bob Hanlon
>



Gregory Lypny

unread,
Apr 5, 2014, 1:46:59 AM4/5/14
to

Works like a charm, but one thing that I struggle with is collecting the values of the variables into one list. For example, of n=4, how would I create a list of values {valueSlider01, valueSlider02, valueSlider03, valueSlider04}?

I've tried a number of variations using ToExpression and Evaluate but always end up with the literal of valueSlider01. etc.

Gregory


Bob Hanlon

unread,
Apr 5, 2014, 1:47:19 AM4/5/14
to

Manipulate[
Manipulate[
Evaluate[Table[
ToExpression[
"valueSlider" <>
StringJoin[ToString /@
IntegerDigits[k, 10, 2]]],
{k, n}]],
Evaluate[Sequence @@ Table[
Row[{
Control[Evaluate[{
{ToExpression[
"nameMenu" <>
StringJoin[ToString /@
IntegerDigits[k, 10, 2]]],
Subsuperscript["name", k, 1]},
Table[
Subsuperscript["name", k, j],
{j, 5}],
ControlType -> PopupMenu}]],
Spacer[25 - 3 Floor[Log10[k]]],
Control[Evaluate[{
{ToExpression[
"valueSlider" <>
StringJoin[ToString /@
IntegerDigits[k, 10, 2]]],
1},
1, 10, 1, Appearance -> "Labeled"}]]}],
{k, n}]]],
{{n, 3, "Number of control pairs"}, Range[10]}]



Bob Hanlon




On Fri, Apr 4, 2014 at 4:49 PM, Gregory Lypny <gregor...@videotron.ca>wrote:

0 new messages