Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Replies: 3   Last Post: Mar 30, 2013 10:11 PM

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Posted: Mar 28, 2013 4:44 PM

On 3/28/2013 11:01 AM, pmassicotte wrote:
...
> Would it be possible to vectorize addtodate? I would like to add
> many different days to a given date. However, addtodate only accept
> 1numeric scalar.
>
>
> But this won't work:
>
>
>
> It would be pretty easy to do with for loop, but I would like to avoid it if possible.

Just use datenum() directly...

A) Include start date...

>> datenum(2000,1, [1:10]')
ans =
730486
730487
730488
730489
730490
730491
730492
730493
730494
730495
>>

Or exclude start date...since days are trivial. This isn't good for
other time intervals because of either floating point roundoff if time
or irregular days/month, etc., for other than days.

>> datenum(2000,1, 1)+[1:10]'
ans =
730487
730488
730489
730490
730491
730492
730493
730494
730495
730496
>>

Exclude start date cleanly -- increment the '1' in the place field.

>> datenum(2000,1, 1+[1:10]')
ans =
730487
730488
730489
730490
730491
730492
730493
730494
730495
730496
>>

NB: that datenum is clever-enough that units roll over properly
accounting for days/month, leapyear, etc., etc., etc., when incrementing.

--

Date Subject Author
3/28/13 Guest
3/28/13 dpb
3/29/13 Guest
3/30/13 dpb