Timer FixedRate - no longer fixed rate after a few days

1 次查看(过去 30 天)
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 个评论
Geoff Hayes
Geoff Hayes 2014-10-24
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.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2014-10-24
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 个评论
Shawn
Shawn 2014-10-27
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by