How to make subplots scroll at the same time?

33 vues (au cours des 30 derniers jours)
LuYao Guo
LuYao Guo le 22 Fév 2021
Commenté : LuYao Guo le 22 Fév 2021
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

Réponse acceptée

Bjorn Gustavsson
Bjorn Gustavsson le 22 Fév 2021
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 commentaire
LuYao Guo
LuYao Guo le 22 Fév 2021
This works exactly what I want! Thank you very much! Great help!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by