1
$\begingroup$

I am working with data and using manipulate function. I have two sets of values in the manipulating variable list which I combine to form a single list. So, the increment which forms the first set won't generate the second set elements of the list. How can I tell slider to specify increments differently for two halves of the manipulating variable? Here is a sample:

I form a manipulating variable set with two different lists:

k1 = Flatten[{Range[-1.61, 0, .1], Sort[-Range[-1.61, 0, .1], #1 < #2 &]}];

Random data as a function of k1 elements for the manipulate Plot:

data = Table[Table[Sin[k x], {x, 1, 5, .1}], {k, k1}];

and finally, Manipulate

Manipulate[ListLinePlot[data[[Position[k1, k][[1, 1]]]], AxesLabel -> {"x", "f"}, 
          BaseStyle -> "Section"], {{k, -1.61, Style["k", 24]}, First[k1], 
          Last[k1], .1, ImageSize -> Large, Appearance -> "Labeled", 
          LabelStyle -> {Black, FontSize -> 25}}, AutorunSequencing -> {{1, 10}}]

This works for one half of the k1's elements but not for the other as 0.1 won't generate the second half. Is there any If conditon or Piecewise operation to incorporate the second half of the k1's elements?

(Note: This is a data-based question so the function Sin[k x] isn't available.)

$\endgroup$
1
$\begingroup$

Use k1 as the iterator list (instead of First[k1], Last[k1], .1) for the contor variable k and specify the control as Manipulator:

Manipulate[ListLinePlot[data[[Position[k1, k][[1, 1]]]], 
   AxesLabel -> {"x", "f"}, BaseStyle -> "Section"],
{{k, -1.61, Style["k", 24]}, k1, Manipulator, 
  ImageSize -> Large, Appearance -> "Labeled", LabelStyle -> {Black, FontSize -> 25}}, 
AutorunSequencing -> {{1, 10}}]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ @klgr thanks a lot.Most of the times I get around the technicalities using a different variation but this was kind of bugging me. Manipulator is exactly what I was looking for. Anything more with Manipulator that can be done such as specifying increment of the slider i.e rather than going through all the values of k1, make slider jump 3 steps at a time? $\endgroup$ – Rupesh Jun 9 '20 at 0:09
  • $\begingroup$ @maeinss, you can use k1[[1;;-1;;3]] instead of k1. $\endgroup$ – kglr Jun 9 '20 at 0:14
  • $\begingroup$ @Klgr got it, thanks $\endgroup$ – Rupesh Jun 9 '20 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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