Zoom in settings resets automatically when new data value are added

조회 수: 7 (최근 30일)
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 CenterFile Exchange에서 Animation에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by