Timer FixedRate - no longer fixed rate after a few days

3 visualizzazioni (ultimi 30 giorni)
Shawn
Shawn il 23 Ott 2014
Commentato: Shawn il 27 Ott 2014
I am trying to log the pressure of a vacuum chamber over long durations. I wrote a script that uses GUIDE, timer, and the serial interface to log the pressure at 100 Hz.
In GUIDE, I create the following timer:
handles.t = timer('ExecutionMode','fixedRate','Period',0.1,'TimerFcn',{'updatePlot_fcn', hObject});
In updatePlot_fcn, I query the serial interface for the pressure data, format the data, plot the data to screen, and place it in a log file.
I found that in the first 24 hours, all my data are recorded (i.e. 10 data points every second). By the second day, I am only logging 7 or 8 data points every second. By the third day, I log on average 2 or 3 data points every second.
I tried the script on several different computer (with > 16GB memory), they all exhibit this problem. I don't know if it is a Matlab memory leak issue (Matlab does not draw additional memory according to task manager), a timer issue, or something wrong that I am doing with the code.
  1 Commento
Geoff Hayes
Geoff Hayes il 24 Ott 2014
Shawn - have you considered doing a test to not write to file (just observe the plot), or start writing to a new file after 24 hours, or not update the plot?
From you pdatePlot_fcn, it looked like you weren't updating the handles.data field, but were still using it to plot the data so I'm not sure what gets displayed (once a second) on that axes.

Accedi per commentare.

Risposte (1)

Jan
Jan il 24 Ott 2014
A new line object is added every 10 calls of the timer function, as far as I can see. With a frequency of 10 Hz (not 100), you have 86400 line obejcts in the axes, and a measurable lag is expected. It is much more efficient to create one line object only and update its 'Data' property iteratively.
  1 Commento
Shawn
Shawn il 27 Ott 2014
If I update the line object, doesn't it replot every data point each time? Wouldn't this take more time? I originally tried this and the plot figure would just freeze.

Accedi per commentare.

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by