Show only amount of n values on a continuous plot
15 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!