updatePlotAfterIntervalExample;
Timer started. Close the figure to stop.
function updatePlotAfterIntervalExample
hAx = axes('Parent', hFig);
t.ExecutionMode = 'fixedRate';
t.TimerFcn = @(obj, event) updatePlot(obj, event, hAx, x, y);
disp('Timer started. Close the figure to stop.');
set(hFig, 'CloseRequestFcn', @(src, evnt) stopAndDeleteTimer(src, t));
function updatePlot(obj, event, hAx, x, y)
newY = sin(x) + 0.1*randn(size(x));
title(hAx, ['Data updated at: ', datestr(now)]);
function stopAndDeleteTimer(src, tmr)
- Run the script. It will start updating the plot every 2 seconds.
- To stop the process, simply close the plot window. The timer will be stopped and deleted automatically.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.