How to make the live plot run in seconds?

11 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2021-3-2
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.
LuYao Guo
LuYao Guo 2021-3-2
Hi Walter, thank you for suggestions. I've edited the part based on your suggestions but the speed of plotting is not changing at all. Do you have more ideas about this? Thank you.

请先登录,再进行评论。

回答(1 个)

Dongyue
Dongyue 2022-11-21
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:

类别

Help CenterFile Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by