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
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2011-2-2
You need to clarify what output you expect.
Why do you have both month and day of the year?
回答(2 个)
Oleg Komarov
2011-2-2
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 个评论
Walter Roberson
2011-2-2
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!