Sorry it's actually Day of the Year, so I need to convert that to Day and Month as well if possible? Thanks
Time and Date
6 views (last 30 days)
Show older comments
I've written some time and date code, but I'm sure there's a better way to do it. I had my data set up as dd:mm:yyyy hh:mm:ss with each one in a separate column with the rest of my input variables, so I did as follows:
load belmontemini;
Day = data(:,2);
Month = data(:,3);
Year = data (:,1);
Hour = data (:,4);
Minute = data (:,5);
Second = data (:,6);
.....
Time = [Day Month Year Hour Second Minute];
C= [Time Evap];
If anyone could point me in the right direction that would be great. I tried to work it out using datenum, but I just couldn't make it work. I'm very new to Matlab, and really confused sorry!!
Thank you.
2 Comments
Walter Roberson
on 2 Feb 2011
You need to clarify what output you expect.
Why do you have both month and day of the year?
Answers (2)
Oleg Komarov
on 2 Feb 2011
Quote: "I had my data set up as dd:mm:yyyy hh:mm:ss with each one in a separate column with the rest of my input variables, so I did as follows"
Not clear...did you have smt like:
- Dates as strings:
data = {'01:01:2004 20:25:33';
'09:02:2005 20:25:42'}
- Dates as datevec output (individual components):
data = [01 01 2004 20 25 33;
09 02 2005 20 25 42];
And what's the result you trying to achieve? Convert to serial date?
- In the first case:
datenum(data, 'dd:mm:yyyy HH:MM:SS')
- In the second case:
datenum(data(:,[3,2,1,4:6]))
Oleg
0 Comments
Walter Roberson
on 2 Feb 2011
If you have the day of year but not the month, then
datenum([Year 0 DayOfYear Hour Minute Second])
will produce a serial date number with the Day Of Year information properly distributed into month and day, taking in to account leap years.
If you need a string output instead, use datestr() with the same input technique.
If you need the vector back again but want the DayOfYear adjusted to month + day, then you can datenum() and datevec() the result of that.
0 Comments
See Also
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!