フィルターのクリア

How to make subplots scroll at the same time?

22 ビュー (過去 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 Center および File ExchangeSubplots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by