Say, I have a list list and I don't want to assign different names to all its elements.

What I want to do it to be able to interactively manipulate any of the elements of list. And if my selection of an element changes, then the slider of its value has to reset to its current value.

This is what I have tried (in fact, all this happens inside a massive DynamicModule inside a Manipulate):

Refresh[x=list[[elementChoice]], TrackedSymbols:>{elementChoice}];
Refresh[list[[elementChoice]]=x, TrackedSymbols:>{x}];
{{elementChoice,1,"Element's number"},1,Length[list],1},{{x,0,"element's value"},0,1}]

but it just resets x to zero if I try to change it.


1 Answer 1


Something like that?

list = Range[0, 9];
DynamicModule[{nr, val},
   Dynamic@list[[ nr]],
   Slider[Dynamic@nr, {1, 10, 1}],
   Slider[Dynamic[list[[ nr]]], {0, 10, 1}]

Manipulate version:

list = Range[0, 9];
 Column[{list, list[[nr]]}],
   Control[{{nr, 1}, 1, 10, 1}],
   Slider[Dynamic[list[[nr]]], {0, 10, 1}]
  • $\begingroup$ This is OK on its own, but is it possible to incorporate something like this into the standard Manipulate environment? For example, if nr is already one of the controls in Manipulate and is used for other evaluations. Then can I put the val slider alongside other controls in Manipulate? $\endgroup$
    – level1807
    Jul 3, 2014 at 13:12
  • $\begingroup$ Wow, I didn't even expect it to be this simple. The "dynamic inside dynamic" stuff always gives me a hard time :) $\endgroup$
    – level1807
    Jul 3, 2014 at 13:30
  • $\begingroup$ @level1807 only the body of Manipulate is wrapped with Dynamic. Try to put nr between Control and Slider, it won't update. $\endgroup$
    – Kuba
    Jul 3, 2014 at 13:32
  • $\begingroup$ Interesting, thank you. $\endgroup$
    – level1807
    Jul 3, 2014 at 13:40
  • $\begingroup$ can I ask you one more question? In the following (incorrect) code Manipulate[DynamicModule[{x}, x = y; Refresh[x = x^p, TrackedSymbols :> {p}]; x], Grid[{{Slider[Dynamic@y, {0, 5}, Appearance -> "Labeled"]}}], {p, 0, 5, Appearance -> "Labeled"}] I want the piece under Refresh only be evaluated when p is changed. Can I do this without removing the structure of DynamicModule inside Manipulate? $\endgroup$
    – level1807
    Jul 3, 2014 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.