Plot Time series data in date format

조회 수: 9 (최근 30일)
dedenlaut
dedenlaut 2011년 12월 9일
Hello,
I confused... if i have input data in .txt
exp : abc.txt
20110313000000 3.87
20110313000015 3.871
20110313000030 3.87
20110313000045 3.869 . . 20110313000130 3.844
20110313000145 3.83
20110313000200 3.824 ..
first column is date format (yyyymmddHHMMSS) and second column is the data
how if I want to plot in X axes in format '2011-March-11 00:15' (yyyy-MM-dd HH:MM)?
I write matlab
load abc.txt;
plot(abc(:,1),abc(:,2));
title('Tide time series 1116');
xlabel('time');
ylabel('Sea water level');
but it didn't give the right plot, anyone can help this basic problem.. thank you

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 9일
You can break up the number in the first column using pure numeric ways similar to what I used in http://www.mathworks.com/matlabcentral/answers/21688-is-there-a-more-effitiant-way-than-datenum-num2str-ftstempin-1-1
And if you don't have a lot of data to input and just want to get the code done, you can instead use
x = datenum(cellstr(num2str(abc(:,1))), 'yyyymmddHHMMSS');
plot(x, abc(:,2))
datetick('x', 'yyyy-mmmm-dd HH:MM');
Note the small modification of your format, from MM to mmmm as MM is minutes but you want the month name which is coded mmmmm
  댓글 수: 1
dedenlaut
dedenlaut 2011년 12월 10일
Thank you Walter...
but I put this code
{load abc.txt;
x=datenum(cellstr(num2str(abc(:,1))),'yyyymmddHHMMSS');
plot(x,abc(:,2))
datetick('x', 'yyyy-mmmm-dd HH:MM');
title('Tide time series 1116');
xlabel('time');
ylabel('Height');}
but show the error
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by