필터 지우기
필터 지우기

Time on X-axis

조회 수: 25 (최근 30일)
Steve
Steve 2012년 2월 28일
댓글: KRUNAL 2014년 8월 12일
I'm and trying to plot real time data in MatLab and I am having trouble determining how to go about putting time on the x-axis. I tried working with 'datenum', but it seems like to use this you would need a predetermined time.
For example I want to see something like 7:30:25 for each tick..
Can this function be used? Would a different function work better to continually update and plot real time?
Thank you

답변 (3개)

Wayne King
Wayne King 2012년 2월 28일
After calling plot() with datenum()
use datetick
datetick('x','HH:MM:SS')
For example:
x = linspace(now, now+1, 12*6+1);
% Create a sample plot
plot(x, (1:length(x)).^2);
datetick('x', 'HH:MM PM')
  댓글 수: 3
Wayne King
Wayne King 2012년 2월 28일
can you give a simple example of your time vector, say 10-20 elements of it and the data. So we can do an example
Steve
Steve 2012년 2월 28일
Maybe I am confused. I don't have a time vector. I was using the example you had illustrated above...I want to plot real time data, so I'm not sure what to put within datenum(). The MatLab help shows a predetermined date.

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


Steve
Steve 2012년 2월 29일
Well I thought I found an answer, but I guess I didn't. I tried using 'clock' which produces a 6 element array that starts with year and ends with seconds. This is what I tried:
c=clock
Time = [(int2str(c(4)) ':' int2str(c(5)) ':' int2str(c(6)))]
In the MatLab command window, it works great. It produced a something like 17:13:34 which is exactly what I want. However, when I try to plot this I get an error:
Unexpected MATLAB expression.
Are there any options for plotting time with data that is contiuously updating?
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 2월 29일
Time = sprintf('%02d:%02d:%02d', c(4), c(5), c(6));
What do you get in the command window if you execute
datestr(linspace(now, now+1, 12*6+1),'HH:MM PM')

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


Steve
Steve 2012년 3월 4일
Time = sprintf('%02d:%02d:%02d', c(4), c(5), c(6));
Thanks Walter, this is what I am looking for. However when I try to use this to plot, I get the following error:
??? Error using ==> plot
Invalid first data argument
Error in ==> GRAPH at 10
plot(Time,Out1)
This is what my code looks like:
count = 0;
Out1 = nan(1, 30);
while count < 3
for i = 1 : 30
num1 = rand + 1;
c=clock;
Out1 = [Out1(2:end), num1];
Time = sprintf('%02d:%02d:%02f', c(4), c(5), c(6));
plot(Time,Out1)
pause(0.1);
end
count = count + 1;
end
  댓글 수: 1
KRUNAL
KRUNAL 2014년 8월 12일
I have date in column 1 and time in column 2 and data in column three. I want to plot date/time against that data. Can anyone tell me how can I do it?

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

카테고리

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