plotting the real time data after certain specified interval in Matlab

时光总嘲笑我的痴心妄想 提交于 2019-12-13 02:09:49

问题


I have a question that I dont know how to figure it out. I am plotting my real time data obtained from temperature sensors in MATLAB. The sensor software generates the text file for each sensor and updates it after every minute. What do I have to do if I want the plot to be updated after certain period of time; let's say after 10 or 20 values or after every 5 mins.


回答1:


You could use a timer.

Reusing the code of Nzbuu, it would be something like the following

function ReadAndUpdate
  [X,Y] = readFile(); % Read file 
  set(h, 'XData', X, 'YData', Y) % Update line data    
end
t = timer('TimerFcn',@ReadAndUpdate, 'Period', 5*60, ...
          'ExecutionMode', 'fixedDelay')
start(t) 

Here the function is trigged infinitely but you can stop it or set a condition.




回答2:


Assuming you have a function readFile that reads the data from the file. You can do the following for something quick and dirty.

h = plot(NaN, NaN);
while true
    [X,Y] = readFile(); % Read file
    set(h, 'XData', X, 'YData', Y) % Update line data
    pause(5*60) % Wait 5 minutes
end


来源:https://stackoverflow.com/questions/7561906/plotting-the-real-time-data-after-certain-specified-interval-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!