Re: Manipulate variables not getting evaluated
- To: mathgroup at smc.vnet.net
- Subject: [mg122849] Re: Manipulate variables not getting evaluated
- From: Armand Tamzarian <mike.honeychurch at gmail.com>
- Date: Sat, 12 Nov 2011 07:34:56 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j9is1j$8h6$1@smc.vnet.net>
On Nov 11, 9:05 pm, Ken Levasseur <klevass... at mac.com> wrote:
> Hello
>
> I'm trying to control, using Manipulate, which rows of a matrix are
> displayed. But have run into a problem. The code I annotate here is
> copied without comments below. For this example, I'll use this 2 by 3
> matrix
>
> A = {{1, 2, 3}, {4, 5, 6}};
>
> The following works pretty much as I intend, although there is fixable
> problem if all boxes are unchecked.
>
> Manipulate[
> Transpose[Transpose[A][[Select[Range[3], {a, b, c}[[#1]] & ]]]],
> Evaluate[Sequence @@ {{a, {True, False}}, {b, {True,
> False}}, {c, {True, False}}}]]
>
> Now I want to do the same for larger matrices with various numbers of
> columns so I've tried generalizing as follows:
>
> Number of columns:
>
> M = 3;
>
> This generates a list of M symbols: col1, col2,=85
>
> switchlist = (ToExpression[StringJoin["col", ToString[#1]]] & ) /@
> Range[M];
>
> This generates a list of controllers for each symbol=85
>
> switches = ({ToExpression[StringJoin["col", ToString[#1]]], {True,
> False}} & ) /@ Range[M];
>
> Now I expected this to work, but it fails:
>
> Manipulate[
> Transpose[Transpose[A][[Select[Range[M], switchlist[[#1]] & ]]]],
> Evaluate[Sequence @@ switches]]
>
> The problem is that the symbols in switchlist don't get evaluated.
>
> Manipulate[switchlist, Evaluate[Sequence @@ switches]]
>
> I've tried using controllers like {{col1,True},{True,False}} and that doesn't make a difference. Any idea why this fails?
>
> Ken Levasseur
> UMass Lowell
>
> ******************
> Code only:
>
> A = {{1, 2, 3}, {4, 5, 6}};
>
> Manipulate[
> Transpose[Transpose[A][[Select[Range[3], {a, b, c}[[#1]] & ]]]],
> Evaluate[Sequence @@ {{a, {True, False}}, {b, {True,
> False}}, {c, {True, False}}}]]
>
> M = 3;
>
> switchlist = (ToExpression[StringJoin["col", ToString[#1]]] & ) /@
> Range[M];
>
> switches = ({ToExpression[StringJoin["col", ToString[#1]]], {True,
> False}} & ) /@ Range[M];
>
> Manipulate[
> Transpose[Transpose[A][[Select[Range[M], switchlist[[#1]] & ]]]],
> Evaluate[Sequence @@ switches]]
>
> Manipulate[switchlist, Evaluate[Sequence @@ switches]]
the final example in Manipulate > Neat Examples is probably the sort
of thing you are looking for:
Manipulate[
ArrayPlot[
Take[data, h, w]], {{data, RandomInteger[{0, 1}, {10, 20}]},
ControlType -> None}, {{h, 5}, 1, 10, 1}, {{w, 5}, 1, 20, 1},
Dynamic[Panel[
Grid[Outer[Checkbox[Dynamic[data[[#1, #2]]], {0, 1}] &, Range[h],
Range[w]]]]]]
Mike