Show only amount of n values on a continuous plot
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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"?
0 commentaires
Réponses (1)
CAM
le 16 Fév 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;
Voir également
Catégories
En savoir plus sur Geographic Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!