Reputation: 4807
I have a data set with 2 columns. The Column 1 is hours from midnight 2013 and Column 2 is quantity. The Column 1 considers the absolute hours from midnight and hence doesn't account for day light savings. How do I generate a Column 3 which is date and Column 4 which is hour from my data.
An idea I had was to correspond the hours to GMT and then change it back to US eastern time. But again I am having trouble implementing it.
This is what I have as a data:
Hours from
midnight 2013 Quantity
28 45
29 74
30 65
31 14
36 13
48 4
This is what I desire:
Hours from
midnight 2013 Quantity Date Hour
28 45 1/2/2014 4
29 74 1/2/2014 5
30 65 1/2/2014 6
31 14 1/2/2014 7
36 13 1/2/2014 12
48 4 1/2/2014 24
Upvotes: 0
Views: 133
Reputation: 13886
OK, here's how I would do it in Octave. The syntax may be slightly different in MATLAB, but the idea is the same:
>> hh = [28 29 30 31 36 48];
>> midnight = datenum(2014,1,1,0,0,0);
>> dates = datestr(midnight+hh/24,'mm/dd/yyyy')
dates =
01/02/2014
01/02/2014
01/02/2014
01/02/2014
01/02/2014
01/03/2014
>> hhs = (midnight+hh/24-datenum(2014,1,2,0,0,0))*24
hhs =
4 5 6 7 12 24
I haven't accounted for day light savings.
Upvotes: 0
Reputation: 1949
I'll do it this way in matlab 2013a:
minuit = [2014 01 01 00 00 00]
col3 = addtodate(datenum(minuit),28,'hour')
then
datestr(col3,'HH') % for your Hour column
datestr(col3,'mm/DD/YYYY') % for your Date colum
Upvotes: 1