Borrar filtros
Borrar filtros

Show only amount of n values on a continuous plot

16 visualizaciones (últimos 30 días)
Christopher
Christopher el 16 de Feb. de 2023
Comentada: Christopher el 16 de Feb. de 2023
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"?

Respuestas (1)

CAM
CAM el 16 de Feb. de 2023
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 comentario
Christopher
Christopher el 16 de Feb. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by