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 want to monitor current results with Dynamic

ls = {}; k = 1;

Dynamic[
 Refresh[
   AppendTo[ls, k++];
   Last@ls
, UpdateInterval -> 10]]

For some reason output updates instantaneously and not every 10 seconds

share|improve this question

3 Answers 3

up vote 10 down vote accepted

When you edit ls, all dynamics that depend on ls will update instantly, this will cause ls to be edited which will update the dynamic which edits ls.... etc.

The way to avoid this is to specify that there should be no tracked symbols:

Dynamic[Refresh[AppendTo[ls, k++];
 Last@ls, UpdateInterval -> 10], TrackedSymbols -> {}]
share|improve this answer

TrackedSymbols is an option to Refresh, Manipulate, and related functions that specifies which symbols should trigger updates when their values are changed.

Dynamic[Refresh[AppendTo[ls, k++]; Last@ls, TrackedSymbols :> {}, UpdateInterval -> 1]]
share|improve this answer

UpdateInterval gives an upper bound to the dynamic updates. It doesn't turn off the automatic updating whenever a symbol that is being tracked gets updated.

Your code has AppendTo[ls, sth]. Imagine that as an equivalent of var=Append[ls, sth]; ls=var; where var is just a dummy to show that first Mathematica builds the list and then it assigns it to ls.

In var=Append[ls, sth], ls gets tracked. Then, ls gets changed with ls=var, triggering a self-update.

One possible solution is to make your dynamic NOT track changes in ls, as the other solutions suggested.

Dynamic[Refresh[AppendTo[ls, k++]; Last@ls, None], UpdateInterval -> 2]
share|improve this answer

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.