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!