Message Boards Message Boards

Access the values of the sliders dynamically via a doloop? (Dynamic@data)

Posted 8 years ago

As a part of a bigger application I am generating n number of sliders to control values of variable in n+2 dimensional function. This way I will plot 2D planes. However, I am unable to access the values of the sliders dynamically via doloop. I can access the data one by one. Any ideas to get around this problem?

Preplot[lims_, midpoints_, limsL_, limsR_, limsteps_] := 
  Module[{}, data = midpoints;
   controls = 
    DynamicModule[{n = Length[midpoints]}, 
     Column[{Dynamic[
        Grid[Table[
          With[{i = i}, {lims[[i]], 
            Slider[Dynamic[data[[i]]], {limsL[[i]], limsR[[i]], 
              limsteps[[i]]}], Dynamic[data[[i]]]}], {i, n}]]], 
       Dynamic[data[[i]]];}, Center]];
   Return[{controls, Dynamic[data]}]];

lims = {x, z, y, p};
midpoints = {0.5, 3, 4.5, 7};
limsL = {0, 2, 3, 4};
limsR = {1, 4, 6, 10};
limsteps = (limsL - limsR)/25;
u = w t x z y p;  (*This is a function I just wrote like this to be \
simple*)

sliders = Preplot[lims, midpoints, limsL, limsR, limsteps][[1]]
(* I can access the values like this but inside a doloop I get an \
error   *)
u = u /. lims[[1]] -> Dynamic@data[[1]];
u = u /. lims[[2]] -> Dynamic@data[[2]];
u = u /. lims[[3]] -> Dynamic@data[[3]];
u = u /. lims[[4]] -> Dynamic@data[[4]];
Print[u];
values = ConstantArray[0, 4];
Do[u2 = u2 /. lims[[i]] -> Dynamic@data[[i]];, {i, n}];
POSTED BY: Erdem Uguz
Posted 8 years ago

to solve the problem Simply replace

Do[u2 = u2 /. lims[[i]] -> Dynamic@data[[i]];, {i, n}];

with

    Dynamic[Do[u2 = u2 /. lims[[i]] -> data[[i]];, {i, n}];
(*whatever you want to do with u2 such as plotting *)  ]

Inside the preplot

POSTED BY: Erdem Uguz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract