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.

This bit of code runs a little animation of a stochastic process:

 (* a random walk bm, its min and max  *)
 {bm, m, M} = {Table[Random[] - .5, {100}] // Accumulate, Min[bm], Max[bm] }

 (* plot of trajectory of bm up to i-th step *)
 traj[i_] := ListLinePlot[({Range[1, 100], bm} // Transpose)[[;; i]], 
    Joined -> True, PlotRange -> {{0, 100}, {m, M}}]

 (* animation using Clock *)
 q = Dynamic[r = Clock[{1, 100, 1}, 5, 1]; traj[r] ]

Next I'd like to use Button to run the animation. Something like

Button["Run", q]

but this doesn't work.

Eventually I'd like to have two buttons, "Repeat" and "Clear" like this:

x = {{0, 0}};   
min[x_] := (Sort[x, #1[[2]] < #2[[2]]  &])[[2]]; Column[ {Row[{Button["Repeat", 
 x = Append[x, { Random[], Random[]  }]], 
Button["Reset", x = { {0, 0}}]  }  ],
Dynamic[Show[{ ListPlot[x, PlotRange -> {{0, 1}, {0, 1}}, ImageSize -> 300, 
  Frame -> True, Axes -> None] , If[Length[x] > 1, 
  Graphics[{Red, Line[{min[x], {min[x][[1]], -.1} }]}], {}],
 If[Length[x] > 1, 
  Graphics[{Red, Line[{min[x], {0, min[x][[2]]} } ]}], {}]
 }]]}]

but instead of dots, I want to plot animated functions involving Clock.

share|improve this question
    
"... part of a screen"? What does that mean? –  zab Apr 26 at 15:44
add comment

1 Answer 1

Have you seen Trigger ?

Panel@Column[{
   Dynamic@traj[r],
   Trigger[Dynamic@r, {1, 100, 1}]
   }]

enter image description here

share|improve this answer
    
Wow, I have not! +1 –  Kuba Apr 26 at 21:08
    
@ Simon, Kuba, Trigger looks useful, but doesn't seem to be working on my Linux version. –  zab Apr 27 at 7:02
    
@Kuba, oh you deleted your answer :-( It was interesting all the same. Anyway, what I have is a function, like q in original post involving Clock Dynamic plots, and works perfectly well with Shift+Return. Now I want to wrap two buttons around it, one to evaluate, and one to repeat. Ordinary functions like Button["Do it", Sin[pi] // Print] work fine, but not if there is a Plot or a Dynamic. Could this be a Linux Mathematica issue? I know that Manipulate sliders never work in Linux. It's a real pain in the trousers, but I'm not switching to Windows just for this. –  zab Apr 27 at 7:53
1  
@zab I don't know why your Slider do not work. I think it is not normal behaviour :) but you have to talk with someone who works on Linux, not me. You can ask separate question for this. About Print you can use CellPrint if you use Cell/BoxData/Toboxes earlier, take a look at documentation of those functions. –  Kuba Apr 27 at 7:57
    
@Kuba, Slider issue is a known problem: mathematica.stackexchange.com/questions/24531/… I will try CellPrint. –  zab Apr 27 at 8:04
show 1 more 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.