How to plot serial data against time

조회 수: 8 (최근 30일)
Jack
Jack 2014년 7월 10일
편집: dpb 2014년 7월 10일
I have an arduino sending serial data every 2 seconds to the serial monitor and Matlab code will read from that serial monitor and plot a graph. The graph plots a value every 2 seconds but how do i make the x -axis equal to time so that the graph shows data is plotted every 2 seconds.

채택된 답변

dpb
dpb 2014년 7월 10일
In real time or just 2-second intervals? If the former see
doc now
doc datetick
doc datenum
If just incremental seconds, just increment a t vector by 2 and use it for the x-axis values.
Note the example in the doc's on animation in the Graphics 2D/3D plots section to do this more efficiently that repetitively calling plot
  댓글 수: 2
Jack
Jack 2014년 7월 10일
thank you, ill just increment a t vector by 2 and use it for the x-axis values. But If im taking multiple readings at different time intervals how do i plot it at real time; datetick and datenum both require a date parameter but i just want seconds
dpb
dpb 2014년 7월 10일
편집: dpb 2014년 7월 10일
Again, that depends on what specific seconds you mean...if it's seconds since the first reading, just subtract that original now value t0 from each current time and then format to seconds.
Altho there you'll probably want to keep the differential as numeric and scale externally because datestr and friends will wrap the SS field modulo 60.
If it's the actual seconds of wall clock when the data were collected, then use the datenum as is but simply format the time portion. Try
for i=1:5,fprintf('%3s',datestr(now,'SS')),pause(2);end,fprintf('\n')
at command line...

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by