convert a time series into a real time animated plot

58 ビュー (過去 30 日間)
Marc Elmeua
Marc Elmeua 2022 年 3 月 26 日
コメント済み: Star Strider 2022 年 3 月 27 日
I am trying, with no success to display a plot of the attached timeseries in a way that it shows like if it was a real-time plotting.
Any help?
Thanks in advance

採用された回答

Star Strider
Star Strider 2022 年 3 月 26 日
Try something like this —
LD = load('timeseries.mat');
time2 = LD.time2;
Time = time2.Time;
Data = time2.Data;
DataRange = [min(Data), max(Data)];
TimeRange = [min(Time), max(Time)];
figure
hold on
for k = 1:numel(Time)-1
plot(Time(k:k+1), Data(k:k+1), '-b')
axis([TimeRange DataRange])
grid
pause(0.0001)
end
hold off
Make appropriate changes to get the desired result.
.
  2 件のコメント
Marc Elmeua
Marc Elmeua 2022 年 3 月 27 日
Thanks everyone for your help. All the scripts work perfectly, yet I find this the most efficient.
PS: if someone has the same problem, maybe this helps: I was writing similar scripts (with drawnow) to the ones proposed in this thread, but I was executing them on a Livescript, hence they were not working properly.
Star Strider
Star Strider 2022 年 3 月 27 日
@Marc ElmeuaThank you!

サインインしてコメントする。

その他の回答 (2 件)

Voss
Voss 2022 年 3 月 26 日
Here's one way:
load('timeseries.mat')
figure();
my_line = line();
for ii = 1:numel(time2.Time)
set(my_line,'XData',time2.Time(1:ii),'YData',time2.Data(1:ii));
drawnow();
end
Alternatively, you can use an animatedline.

Walter Roberson
Walter Roberson 2022 年 3 月 26 日
Times = time2.Time;
Data = time2.Data;
N = 10; %at a time -- one at a time is very slow
nsamp = length(Times);
h = animatedline();
for K = 1 : N : nsamp
idx = K : min(K+N-1, nsamp);
addpoints(h, Times(idx), Data(idx));
drawnow();
end

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by