Refreshing Plot After Certain Time?

Hi all,
I'm writing a GUI in App Designer to live plot spirometry data from LabChart. The end goal is to have a participant match the square wave by sniffing in. So, I want the data to be plotted live, then reset to the beginning every 6 seconds. My solution below does not work, the data doesn't even plot.
function plotter = plot_data(app,~,~)
global gLCDoc;
global gChans;
global gChansData;
% gChansData is the live Y-axis data pulled from LabChart
gChansData = gLCDoc.GetChannelData(1,gChans,gLatestBlock+1, length(gChansData(1))+1, -1);
% 6 seconds is an arbitrary number
% My attempted solution is to clear the data points every 6000 ms
% To find that, I use an if statement and the modulus of data length and 6000
if mod(length(gChansData),6000) == 0
gChansData(1:6000) = [];
app.UIAxes.cla;
app.UIAxes.XTick = [0:1000:6000];
app.UIAxes.XLim = [0 6000];
app.UIAxes.YLim = [-600 800];
base_x = [0 2000 2000 4000 4000 6000];
base_y = [0 0 450 450 0 0];
plot(app.UIAxes,base_x,base_y);
%plot
plot(app.UIAxes,gChansData,'r');
else
plot(app.UIAxes,gChansData,'r');
end
end
% Another if statement I tried that didn't work:
if ~mod(length(gChansData),6000) > 0
%Timer refreshes axes by calling function every .01 seconds
Timer = timer('ExecutionMode','fixedRate','Period',.01);
Timer.TimerFcn = {@app.plot_data};
start(Timer);

Réponses (1)

Mario Malic
Mario Malic le 4 Sep 2020

0 votes

Use function drawnow to refresh the plots.
If I understood the code correctly, you just need to add drawnow somewhere after plots.

Community Treasure Hunt

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

Start Hunting!

Translated by