How to make subplots scroll at the same time?
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
LuYao Guo
el 22 de Feb. de 2021
Comentada: LuYao Guo
el 22 de Feb. de 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
0 comentarios
Respuesta aceptada
Bjorn Gustavsson
el 22 de Feb. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!