Re: converting dates to intervals
- From: dpb <none@xxxxxxx>
- Date: Wed, 25 Nov 2009 15:14:06 -0600
Janis Weir wrote:
dpb <none@xxxxxxx> wrote in message <hek4h4$fnt$1@xxxxxxxxxxxxxxxxxxxxxxxxxx>...Janis Weir wrote:dpb <none@xxxxxxx> wrote in message <hek15v$fui$1@xxxxxxxxxxxxxxxxxxxxxxxxxx>...Use datenum() on the time string then pass that to datevec()Janis Weir wrote:However, once I import this data into Matlab the same value isdpb <none@xxxxxxx> wrote in message <hejrod$sjg$1@xxxxxxxxxxxxxxxxxxxxxxxxxx>......Janis Weir wrote:>> datestr(datenum(x,x,x,h,m,s),13)>> ts={'08:01:04' '08:09:31' '08:11:09'};Starting at 08:00:00 I would like to consolidate date into 5-minute
intervals. I don't want to consolidate to the nearest 5-min
interval, but rather to the interval within which the datetime
falls. Take 13/04/1987 08:09:31, for example. I don't want to
round to the nearest 5-minute interval, ie: 08:10:00, but rather to
08:05:00. ...
>> [x,x,x,h,m,s]=datevec(ts);
>> m = m-mod(m,5)
m =
0
5
10
>> s = 0;
Put back into string w/ datestr()
--Perfect, thanks. Quick question, once I have broken down the
datevec into individual h, m, and s vectors, how do I reverse this
and consolidate h, m, and s into one vector that I can then use the
datestr() command on?
ans =
08:00:00
08:05:00
08:10:00
>>
In the whole thing you may have to keep mn,da,yr as well depending on whether the string is one or two or how you choose to treat it...I simply used the time string for example...x==0 here, of course.
--The dates in my excel file are formatted like this: 11/01/2002 14:37
formatted lie this: '11/01/2002 2:37:35 PM' in which case the above
code does not work. Any suggestions?
Alternatively, if you have a current version of ML I believe datevec() now has the option to specify a date/time format string. Which version introduced that I don't know; it postdates mine so consult your documentation.
Alternatively, I don't know if there's a way to force the 24-hr format when importing or not w/ some of the later versions rather than the default of am/pm (which seems a silly thing to do imo, but TMW didn't ask :) (me at least) ).
--I have tried to specify a date/time format string with datevec,
but it does not seem to work.
Does your doc indicate that your version accepts it? I can't test it but a quick look at the current doc's indicates it should be possible (at least I think). What did you try specifically? Sample code is always better than "didn't work" (just as we didn't get anywhere at all until you provided a clear definition of what you expected).
you mean by using datenum() on the time string then passing it to
datevec(). I'm not sure that I follow. Both the date and time are
combined within a single cell of my series.
Exactly that...
>> datevec(datenum('2:37:35 PM'))
ans =
0 0 0 14.0000 37.0000 35.0000
>> datevec(datenum('11/3/2002 2:37:35 PM'))
ans =
2002 11 3 14 37 35
>>
If your series are quite long it might be a performance boost to separate out the date/time strings and work on only the time part, I don't know. I've never used ML date stuff "in anger", only in small stuff like this.
You can start off altogether and see if there's an issue, of course.
--
.
- References:
- converting dates to intervals
- From: Janis Weir
- Re: converting dates to intervals
- From: dpb
- Re: converting dates to intervals
- From: Janis Weir
- Re: converting dates to intervals
- From: dpb
- Re: converting dates to intervals
- From: Janis Weir
- Re: converting dates to intervals
- From: dpb
- Re: converting dates to intervals
- From: Janis Weir
- Re: converting dates to intervals
- From: dpb
- Re: converting dates to intervals
- From: Janis Weir
- converting dates to intervals
- Prev by Date: error message on ode15s?
- Next by Date: MATLAB Fcn -- output structure
- Previous by thread: Re: converting dates to intervals
- Next by thread: how to find the corresponding value to the most repetitive value in hist diagram
- Index(es):
Relevant Pages
|