Show only amount of n values on a continuous plot
    조회 수: 12 (최근 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에서 Graphics Performance에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

