Zoom in settings resets automatically when new data value are added

7 ビュー (過去 30 日間)
Kishore Kumar
Kishore Kumar 2021 年 10 月 25 日
コメント済み: Kishore Kumar 2021 年 12 月 7 日
I am trying to plot a real time data from a hardware. I want new data values to be plotted and connected to previous data points.
So I am using animatedline() addpoints() command to plot new points and the plot looks good.
When I perform vertical zoom in to see the change in data, the zoom options resets automatically when it adds a new datapoint. I want the zoom in to be enabled till I manually hit the zoom out button.
How could i hold the zoom settings when new data pionts are added in the graph?
Thank you for any help.
  2 件のコメント
jagadeeshwar tabjula
jagadeeshwar tabjula 2021 年 12 月 6 日
Hi Kishore,
I am also looking for the solution to this problem. Please update if you find an answer for it.
Regards
Jagadeeshwar
Kishore Kumar
Kishore Kumar 2021 年 12 月 7 日
Please check if the answer helps.

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

採用された回答

Kishore Kumar
Kishore Kumar 2021 年 12 月 7 日
Thank you jagadeeshwaran for reminding me to update my answer.
Here I have included a sample code
%test animated line
anim= animatedline('Marker','o');
h1=animatedline('marker','o','color','r');
h2=animatedline('marker','o','color','k');
h3=animatedline('marker','o','color','b');
h4=animatedline('marker','o','color','#7E2F8E');
for i=1:2000
addpoints(h1,i,rand+10);
addpoints(h2,i,rand+20);
addpoints(h3,i,rand+30);
addpoints(h4,i,rand+40);
drawnow limitrate;
if i<100
axis([0 i 0 50])
else
axis([i-100 i 0 50])
end
end
I was trying to update the X axis with last 100 values so that graphs shows a closer view on the latest values.
Pls note that I used
axis([i-100 i 0 50])
command inside for loop which resets the "zoom in" that I perform in plot window.
You could rather use xlim and ylim commands which can force the xlim alone to update with new range of values and the yaxis will be in your control.
%test animated line
anim= animatedline('Marker','o');
h1=animatedline('marker','o','color','r');
h2=animatedline('marker','o','color','k');
h3=animatedline('marker','o','color','b');
h4=animatedline('marker','o','color','#7E2F8E');
ylim([0 50])
for i=1:2000
addpoints(h1,i,rand+10);
addpoints(h2,i,rand+20);
addpoints(h3,i,rand+30);
addpoints(h4,i,rand+40);
drawnow limitrate;
if i<100
xlim([0 i])
else
xlim([i-100 i])
end
end
Here ylimits is initialized outside the for loop and Xlimits are alone updated in the loop. So this will allow to zoom in to any particular y axis range.
Use you use drawnow limitrate to render graphs faster and it also allows user callbacks.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by