Filter löschen
Filter löschen

Time and Date

1 Ansicht (letzte 30 Tage)
Claire
Claire am 2 Feb. 2011
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 Kommentare
Claire
Claire am 2 Feb. 2011
Sorry it's actually Day of the Year, so I need to convert that to Day and Month as well if possible? Thanks
Walter Roberson
Walter Roberson am 2 Feb. 2011
You need to clarify what output you expect.
Why do you have both month and day of the year?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Oleg Komarov
Oleg Komarov am 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

Walter Roberson
Walter Roberson am 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.

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by