필터 지우기
필터 지우기

How to make subplots scroll at the same time?

조회 수: 27 (최근 30일)
LuYao Guo
LuYao Guo 2021년 2월 22일
댓글: LuYao Guo 2021년 2월 22일
Hi, I have a problem about plotting two scrollable subplots in sync, where from my code, the second plot works correctly as I want. But the first plot fails to move. What I want is making these two waves moves at the same time, in a live way. Can someone helps me please? Thank you!
%Plot two channels
clear
clc
close all
h = figure;
%a1 = animatedline('Color',[0 .7 .7]);
fs = 250;
opts = detectImportOptions("testing.txt");
%opts.VariableNamesLine = 1;
C = readtable('testing.txt');
A = table2array(C(:,23));
%t = linspace(0,20,length(A));
t = (0:height(C)-1)/fs;
%Create subplot
subplot(2,1,1);
axis([0 30 0 18000]);
a1 = animatedline('Color',[0 1 1]);
subplot(2,1,2);
axis([0 30 0 18000]);
a2 = animatedline('Color',[0 1 1]);
axis tight
for k = 1:height(C)
%Guard addpoints call with check
addpoints(a1,t(k),(-1)*C.EXGChannel1(k));
hold on
addpoints(a2,t(k),C.EXGChannel6(k));
xlim([max(0,t(k)-30) max(30,t(k))]);
drawnow limitrate
end

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 2월 22일
See the help and documentation for linkaxes (and possibly linkprop). I'd do something like this:
%Create subplot
sph1 = subplot(2,1,1);
axis([0 30 0 18000]);
a1 = animatedline('Color',[0 1 1]);
sph2 = subplot(2,1,2);
axis([0 30 0 18000]);
a2 = animatedline('Color',[0 1 1]);
axis tight
linkaxes([sph1,sph2])
for k = 1:height(C)
%Guard addpoints call with check
addpoints(a1,t(k),(-1)*C.EXGChannel1(k));
hold on
addpoints(a2,t(k),C.EXGChannel6(k));
xlim([max(0,t(k)-30) max(30,t(k))]);
drawnow limitrate
end
Maybe you need to set the linkaxes call inside the loop where you add points.
HTH
  댓글 수: 1
LuYao Guo
LuYao Guo 2021년 2월 22일
This works exactly what I want! Thank you very much! Great help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by