Problem with datenum (R2012a)

1 次查看(过去 30 天)
Hello,
I'm a French student, and I need your help about datenum.
I want to use it with Year Month Day and Hour The problem is that it don't work fine, I only can do Year Month Day or Year Month Day Hour Minute Seconds.
I tried to create myself a time vector to go over this problem but it don't work.
I've to read data of [Rn] and [CH4] hour per hour over 1 month of data, each measure should have a number that datenum should do...
Matlab version is R2012a
Thanks in advance for the help

采纳的回答

Kelly Kearney
Kelly Kearney 2014-10-28
Based on your data...
% Data snippet
data = [...
2011 06 01 00 1898.800 0.423
2011 06 01 01 1905.340 0.765
2011 06 01 02 1901.140 0.685
2011 06 01 03 1900.540 0.740
2011 06 01 04 1905.690 0.739
2011 06 01 05 1922.490 0.995];
% Datenumbers
dn = datenum([data(:,1:4) zeros(size(data,1),2)])
% Hours elapsed relative to first point
hr = (dn - dn(1))*24
  1 个评论
Sylvain
Sylvain 2014-10-28
编辑:Sylvain 2014-10-28
Yes, it works ! with all data I have a graph with [Rn] and [CH4] for the month, thanks ! My prof wanted that I use dlmread function instead to get 720 lines of data in the script file and I arranged it ;)

请先登录,再进行评论。

更多回答(2 个)

Daniel
Daniel 2014-10-28
the function datestr takes an optional second argument where you can explicitly set the display format
datestr(now,'yyyy-mm-dd HH')
the full list of options can be found in the documentation for datestr
  1 个评论
Sylvain
Sylvain 2014-10-28
编辑:Sylvain 2014-10-28
Thanks, but I want to create a datenum, that when you read yyyy dd mm HH format, you have a whole number, what I have to do so? Data go from 2011 06 01 00 to 2011 06 30 23 (so it will go from 1 to 720 normally) I hope you understand what I said (see attachment)
Thanks again

请先登录,再进行评论。


Chad Greene
Chad Greene 2014-10-28
Here's 40 days worth of hourly datenums:
t_hourly = datenum(2014,1,1,0:40*24,0,0);
datestr(t_hourly)
Or, if you have some data at other intervals, you can round it to the nearest hour like this. Perhaps your data are in 35 minute intervals:
t_35 = datenum(2014,1,1,0,0:35:40*24*60,0);
[year,month,day,hour,minute,second] = datevec(t_35);
t_hourly_rounded = datenum(year,month,day,round(hour),0,0);
datestr(t_hourly_rounded)
  2 个评论
Sylvain
Sylvain 2014-10-28
Thanks, see my attachment above, the goal is creating datenum, your tip works fine ! So for my exercise it should be like this :
t_hourly=datenum(2011,6,1,0,0:30*24,0,0);
datenum(t_hourly)
Is it right?
Chad Greene
Chad Greene 2014-10-28
Oh, I see your text file. Kelly's answer looks right.

请先登录,再进行评论。

类别

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