Problem with datenum (R2012a)
Show older comments
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
Accepted Answer
More Answers (2)
Daniel
on 28 Oct 2014
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 Comment
Chad Greene
on 28 Oct 2014
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 Comments
Sylvain
on 28 Oct 2014
Chad Greene
on 28 Oct 2014
Oh, I see your text file. Kelly's answer looks right.
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!