How to make subplots scroll at the same time?

19 次查看(过去 30 天)
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

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by