Timer FixedRate - no longer fixed rate after a few days

1 view (last 30 days)
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 Comment
Geoff Hayes
Geoff Hayes on 24 Oct 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.

Sign in to comment.

Answers (1)

Jan
Jan on 24 Oct 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 Comment
Shawn
Shawn on 27 Oct 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.

Sign in to comment.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!