Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6377 > unrolled thread

Manipulate variables not getting evaluated

Started byKen Levasseur <klevasseur@mac.com>
First post2011-11-11 10:05 +0000
Last post2011-11-12 12:38 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Manipulate variables not getting evaluated Ken Levasseur <klevasseur@mac.com> - 2011-11-11 10:05 +0000
    Re: Manipulate variables not getting evaluated Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-11-12 12:38 +0000

#6377 — Manipulate variables not getting evaluated

FromKen Levasseur <klevasseur@mac.com>
Date2011-11-11 10:05 +0000
SubjectManipulate variables not getting evaluated
Message-ID<j9is1j$8h6$1@smc.vnet.net>
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]]

[toc] | [next] | [standalone]


#6403

FromArmand Tamzarian <mike.honeychurch@gmail.com>
Date2011-11-12 12:38 +0000
Message-ID<j9lpcp$lgi$1@smc.vnet.net>
In reply to#6377
On Nov 11, 9:05 pm, Ken Levasseur <klevass...@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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web