Plot Time series data in date format

6 次查看(过去 30 天)
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