问题
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