Reputation: 145
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.
Upvotes: 1
Views: 2860
Reputation: 3032
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.
Upvotes: 2
Reputation: 5251
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
Upvotes: 0