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


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

How to define a localized indexed object in Manipulate?

Started by"Nasser M. Abbasi" <nma@12000.org>
First post2011-12-18 09:40 +0000
Last post2011-12-21 11:53 +0000
Articles 3 — 2 participants

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


Contents

  How to define a localized indexed object in Manipulate? "Nasser M. Abbasi" <nma@12000.org> - 2011-12-18 09:40 +0000
    Re: How to define a localized indexed object in Manipulate? Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-12-19 12:15 +0000
      Re: How to define a localized indexed object in Manipulate? "Nasser M. Abbasi" <nma@12000.org> - 2011-12-21 11:53 +0000

#7331 — How to define a localized indexed object in Manipulate?

From"Nasser M. Abbasi" <nma@12000.org>
Date2011-12-18 09:40 +0000
SubjectHow to define a localized indexed object in Manipulate?
Message-ID<jckcdj$1mc$1@smc.vnet.net>
Hello,

Any one knows how to define and use an indexed object in Manipulate?

Looking at the example below, p@x is an indexed object used by
Manipulate.

--------------------------------
Manipulate[
   p@x=p@x+1;
   n;
   Row[{"p@x=",p@x}],

   Button["click to update p@x",n++],
   {{n,0},None},
   TrackedSymbols:>{n},

   Initialization:>
   {
     p@x=0
   }
]
--------------------------------

But in the above, I had to put p@x in the  Initialization section
because I did not know how to make a Manipulate Dynamic. This
makes p@x become global, and will not be localized when one makes
a new copy of the Manipulate snapshot, causing a problem.

The obvious solution, which is to add

{{p@x,0},None}

to make p@x become a Manipulate own Dynamic, does not work for
indexed object. So, I could not do the following:

--------------------------------
Manipulate[
   p@x=p@x+1;
   n;
   Row[{"p@x=",p@x}],

   Button["click to update p@x",n++],
   {{n,0},None},
   {{p@x,0},None},    (* DOES NOT WORK, what is the synatx to use?*)
   TrackedSymbols:>{n}
]
--------------------------------

Any tick or hint how to do this will be great.

Thank you,
--Nasser

[toc] | [next] | [standalone]


#7334

FromArmand Tamzarian <mike.honeychurch@gmail.com>
Date2011-12-19 12:15 +0000
Message-ID<jcn9tk$e1t$1@smc.vnet.net>
In reply to#7331
On Dec 18, 8:40 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> Hello,
>
> Any one knows how to define and use an indexed object in Manipulate?
>
> Looking at the example below, p@x is an indexed object used by
> Manipulate.
>
> --------------------------------
> Manipulate[
>    p@x=p@x+1;
>    n;
>    Row[{"p@x=",p@x}],
>
>    Button["click to update p@x",n++],
>    {{n,0},None},
>    TrackedSymbols:>{n},
>
>    Initialization:>
>    {
>      p@x=0
>    }
> ]
> --------------------------------
>
> But in the above, I had to put p@x in the  Initialization section
> because I did not know how to make a Manipulate Dynamic. This
> makes p@x become global, and will not be localized when one makes
> a new copy of the Manipulate snapshot, causing a problem.
>
> The obvious solution, which is to add
>
> {{p@x,0},None}
>
> to make p@x become a Manipulate own Dynamic, does not work for
> indexed object. So, I could not do the following:
>
> --------------------------------
> Manipulate[
>    p@x=p@x+1;
>    n;
>    Row[{"p@x=",p@x}],
>
>    Button["click to update p@x",n++],
>    {{n,0},None},
>    {{p@x,0},None},    (* DOES NOT WORK, what is the synatx to use=
?*)
>    TrackedSymbols:>{n}
> ]
> --------------------------------
>
> Any tick or hint how to do this will be great.
>
> Thank you,
> --Nasser

You appear to be asking for the following:

1. keep all symbols local; and

2. have p[x] update incrementally when n changes; and

3. the solution must be a Manipulate.

One possible solution that fits that criteria is this:

Manipulate[
DynamicModule[{p, x},
  p@x = 0;

  Column[{
  	Dynamic[p@x += 1; n, TrackedSymbols :> {n}],
  	Dynamic@Row[{"p@x=",p@x}]
  }],

 {{n, 0, "n"}, 0, 10, 1}]


Mike

[toc] | [prev] | [next] | [standalone]


#7374

From"Nasser M. Abbasi" <nma@12000.org>
Date2011-12-21 11:53 +0000
Message-ID<jcshc6$267$1@smc.vnet.net>
In reply to#7334
On 12/19/2011 6:15 AM, Armand Tamzarian wrote:

>
> You appear to be asking for the following:
>
> 1. keep all symbols local; and
>
> 2. have p[x] update incrementally when n changes; and
>
> 3. the solution must be a Manipulate.
>
> One possible solution that fits that criteria is this:
>
> Manipulate[
> DynamicModule[{p, x},
>    p@x = 0;
>
>    Column[{
>    	Dynamic[p@x += 1; n, TrackedSymbols :>  {n}],
>    	Dynamic@Row[{"p@x=",p@x}]
>    }],
>
>   {{n, 0, "n"}, 0, 10, 1}]
>
>
> Mike
>

Thanks Mike, yes, your solution solves the problem I had.

--Nasser

[toc] | [prev] | [standalone]


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


csiph-web