How to make the live plot run in seconds?

조회 수: 20 (최근 30일)
LuYao Guo
LuYao Guo 2021년 3월 2일
답변: Dongyue 2022년 11월 21일
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