Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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):

list=Table[0,{i,1,100}];
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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Something like that?

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

Manipulate version:

list = Range[0, 9];
Manipulate[
 Column[{list, list[[nr]]}],
 Column[{
   Control[{{nr, 1}, 1, 10, 1}],
   Slider[Dynamic[list[[nr]]], {0, 10, 1}]
   }]]
share|improve this answer
    
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? –  level1807 Jul 3 at 13:12
    
Wow, I didn't even expect it to be this simple. The "dynamic inside dynamic" stuff always gives me a hard time :) –  level1807 Jul 3 at 13:30
    
@level1807 only the body of Manipulate is wrapped with Dynamic. Try to put nr between Control and Slider, it won't update. –  Kuba Jul 3 at 13:32
    
Interesting, thank you. –  level1807 Jul 3 at 13:40
    
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? –  level1807 Jul 3 at 18:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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