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 question already has an answer here:

This seems to me to be a very easy question, but I can't seem to figure it out. Instead of updating every 1 second, it auto-updates as quickly as possible.

t = 1; Dynamic[Refresh[t++, UpdateInterval -> 1, TrackedSymbols :> {t}]]

I've checked the documentation to no avail. Could someone explain this behaviour an propose a fix?

share|improve this question

marked as duplicate by Kuba, m_goldberg, bobthechemist, Jens, Michael E2 Jul 23 '14 at 3:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

From the docs: "UpdateInterval->t specifies that updating should, if possible, be done at least every t seconds." You could use a scheduled task to update a symbol, and then display the symbol with Dynamic. –  mfvonh Jul 22 '14 at 15:02
@mfvonh I have edited the question to clarify my problem. –  E.O. Jul 22 '14 at 15:10
closely related –  Kuba Jul 22 '14 at 15:46
@Kuba That seems like a duplicate. Do you not think so? –  Mr.Wizard Jul 22 '14 at 17:58
@Mr.Wizard I think so but no 100% sure. Sure enought to cast a close-vote though :) –  Kuba Jul 22 '14 at 22:03

2 Answers 2

up vote 3 down vote accepted

When a Symbol is "tracked" it means that when its value changes the Dynamic expression is refreshed, therefore your input updates as fast as possible because every refresh changes the value of t which causes a refresh which... you get the picture.



t = 1; Dynamic[Refresh[t++, UpdateInterval -> 1, TrackedSymbols -> {}]]
share|improve this answer

Refresh only sets a limit on how long expression can go without being updated. To keep t form being updated more often add a pause.

t = 1; Dynamic[Refresh[Pause[1]; t++, UpdateInterval -> 1, TrackedSymbols :> {t}]]

or do what Mr.Wizard indicated, which is better.

But this sort of thing is best done by higher level constructs such as Clock or Trigger. For example:

status[t_, t1_] := Row[{t, " > ", threshold, " is ", t > t1}]

Dynamic[With[{dt = 1, tmax = 10, threshold = 4}, 
  t = Clock[{0, tmax, dt}, tmax, 1]; status[t, threshold]]]

The above will run for 10 seconds and will update once a second showing whether or not the value of t has passed t = 4.

Trigger gives more control. The following does what the previous example does, but allows the process to be paused and restarted further, the process can be repeated without re-evaluating the code.

With[{dt = 1, tmax = 10, threshold = 4},
    Dynamic @ status[t, threshold],
    Trigger[Dynamic@t, {0, tmax, dt}, dt, 
      AppearanceElements -> {"PlayPauseButton", "ResetButton"}]}]]
share|improve this answer

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