How to make the live plot run in seconds?
9 views (last 30 days)
Show older comments
Hello,
Can somebody please help me debug this code? I'm using a EEG data where records eye blink happens every 3 seconds. And I want to plot this in real time (second). But when I use code
drawnow limitrate
The plots seems faster than I expect. I also try 'drawnow', which gives me really slow drawing.
%Plot two channels without filters
clear
clc
close all
h = figure;
%a1 = animatedline('Color',[0 .7 .7]);
axis tight
%Sampling Frequency = 250
fs = 250;
opts = detectImportOptions("blink.txt");
%opts.VariableNamesLine = 1;
C = readtable('blink.txt');
A = table2array(C(:,23));
t = (1:height(C))/fs;
%Create subplot
sph1 = subplot(2,1,1);
axis([0 10 -18000 0]);
a1 = animatedline('Color',[0 1 1]);
xlabel('time in seconds');
ylabel('uV');
title('EEG signals in channel 1');
sph2 = subplot(2,1,2);
axis([0 10 0 18000]);
a2 = animatedline('Color',[0 1 1]);
xlabel('time in seconds');
ylabel('uV');
linkaxes([sph1,sph2],'x');
for k = 1:height(C)
%Guard addpoints call with check
addpoints(a1,t(k),C.EXGChannel1(k));
hold on
addpoints(a2,t(k),C.EXGChannel6(k));
%For scrolling window
xlim([max(0,t(k)-30) max(30,t(k))]);
%ylim('auto');
%xlimit = [t(k)-30,t(k)];
%set(a1,'xlim',xlimit);
%set([a1,a2],'xlim',xlimit);
drawnow limitrate
end
I appreciate a lot for your help!
2 Comments
Walter Roberson
on 2 Mar 2021
Do not call hold on inside the loop. You are not adding any new graphics objects inside the loop.
Your animated lines are in two different subplots, but you are only adjusting the limit on one of them. You do link the 'x' properties, but you do not link the XLim properties.
Answers (1)
Dongyue
on 21 Nov 2022
Hi LuYao, you can try to use pause(1) in your loop, which can stop the iteration for 1 second each turn. For more details, please go through the link below:
0 Comments
See Also
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!