2
$\begingroup$

Is there a way (ideally simple) to combing SetterBar with other manipulate controls? Such as have a manipulater parameter inside the SetterBar definition.

Here I would like to use m and n to select parts of data set. The first example, I do it manually before manipulate. The second example was my idea how I would like to have m and n implemented in the SetterBar functions. Obviously it does not work since there is cross dependence.

data = RandomReal[1, 100];
m = 10;
n = 30;
Manipulate[
 ListLinePlot[{data[[m ;; n]], 
   d}], {d, {MovingAverage[data[[m ;; n]], 3] -> "MOA", 
   GaussianFilter[data[[m ;; n]], 3] -> "Gauss"}}]
Manipulate[
 ListLinePlot[{data[[m ;; n]], 
   d}], {d, {MovingAverage[data[[m ;; n]], 3] -> "MOA", 
   GaussianFilter[data[[m ;; n]], 3] -> "Gauss"}}, {m, 1, Length@data,
   1}, {n, 10, Length@data, 1}]
$\endgroup$

2 Answers 2

2
$\begingroup$

Use IntervalSlider.

Manipulate[
  ListLinePlot[{Take[data, interval], func[Take[data, interval]]}], 
  {func, 
     {MovingAverage[#, 3] & -> "MOA", 
      GaussianFilter[#, 3] & -> "Gauss"}, 
   ControlType -> SetterBar}, 
  {{interval, {1, Length@data}}, 1, Length@data, 1, 
   IntervalSlider, Method -> "Push", 
   MinIntervalSize -> 2}]
$\endgroup$
0
$\begingroup$

To simplify, I calculate the averaged data before plotting and use a simple variable to choose the average method:

Manipulate[If[n <= m + 2, n = m + 3];
 dma = MovingAverage[data[[m ;; n]], 3]; 
 dg = GaussianFilter[data[[m ;; n]], 3];
 ListLinePlot[{data[[m ;; n]], If[d == "MOA", dma, dg]}]
 , {{m, 1}, 1, Length@data - 3, 1}, {{n, Length[data]}, 2, 
  Length[data], 1}, {{d, "MOA"}, {"MOA", "Gauss"}}]

enter image description here

$\endgroup$

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.