Show only amount of n values on a continuous plot

조회 수: 15 (최근 30일)
Christopher
Christopher 2023년 2월 16일
댓글: Christopher 2023년 2월 16일
I read data from the serial port once a second and give each data point a time. Then I plot this data point(y) over time(x) and create a continuous plot.
Therefore, the plot is countinuously getting longer in x direction the more values are read in and gets unreadable after some time due to the x axis beeing scaled down. Since I don't know when my last x-value will be read in(it should run for days when done), I also cannot set a limit to the x-axis.
To keep it readable and I want to only show the last 10 values but still be able to move the x-axis and see the older points if needed.
Does anyone know how to show just this "window"?

답변 (1개)

CAM
CAM 2023년 2월 16일
I presume that you are reading the serial data into a timetable or set of vectors (Time, Data, ...). Instead of plotting the whole table/vector, pull the last 10 entries into a separate variable and update the XData and YData in the line object (as opposed to replotting every time).
p=plot(Time, Data); % Original plot. Creates line object
% <...>
% At each data update
t_plot = Time(end-9:end);
d_plot = Data(end-9:end);
p.XData = t_plot; p.YData = d_plot;
  댓글 수: 1
Christopher
Christopher 2023년 2월 16일
Thank you for the answer!
I update only with the newest value and keep the old data via hold.
With your given code the plot only shows the last 10 values then, the values before are not in the plot anymore as I overwrite them with this.
I want to have all values in the plot, but want to only see the newest 10, without losing the ones before.
Just like an oscillocope does, just with the option to "scroll back" on the x axis as you can do when zoomed in.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by