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.

I'm trying to setup a Manipulate where I have a variable number of sliders similar to this one, where every slider controls a function. In my case, there will be an additional slider which sets the number of functions.

I've tried with

Manipulate[
  Block[{},
    Manipulate @@ 
      {Plot[Table[Cos[2\[Pi]Subscript[h, i]x], {i, 1, n}], {x, 0, 1}], 
       Sequence@@Table[{Subscript[h, i], 0, 1}, {i, n}]}], 
  {{n, 1, "Waves"}, 1, 4, 1}]

but that does not work. I hope I have been successful in explaining my problem.

For instance this is partially working, except I can not add controls on functions, i.e. Subscript[h,i] in a nested manipulate

Manipulate[
  Block[{
    trange = {t, 0, tmax},
    plotrange = {{0, xmax}, {-1, 1}},
    aspectratio = 1/xmax,
    f = Table[Cos[2 \[Pi] i t], {i, 1, n}]
    },
    Plot[Evaluate[f], Evaluate[trange], PlotRange -> plotrange, 
    AspectRatio -> aspectratio]
    ],
  {tmax, 0.1, 1},
  {xmax, 0.1, 1},
  {n, 1, 4, 1}
]
share|improve this question
add comment

1 Answer 1

In your construction, it will evaluate {Plot[...],..} first and then apply Manipulate. Plot[..] will become empty graphics since it didn't know about Subscript[h,1]. The following will be the better construction for this purpose:

Manipulate[
 With[{controls = Sequence @@ Table[{Subscript[h, i], 0, 1}, {i, 1, n}], 
       func = Table[Cos[2 \[Pi] Subscript[h, i] x], {i, 1, n}]}, 
       Manipulate[Plot[func, {x, 0, 1}], controls, Paneled -> False]], 
 {n, 1, 10, 1}]
share|improve this answer
    
Great now it works perfectly. I am figuring what went wrong... Thank You very much! However, it does not save the values for the sliders, i.e. they clear every time I change n. –  Fabio Oct 31 '13 at 9:11
add comment

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.