質問

I need to subtract months from a given DateCol in a matrix. I was using the command bsxfun(@minus, datevec(date),[0,3,0,0,0,0]) to subtract 3 months from the given date. You can see there is a bug in this code. If the date is 1-Feb-2011, this code takes you to 1-Jan-2011 instead and NOT 1-Nov-2010.

mat = [100 734505 ; 200 734536 ; 200 734539] ; % Col1 is ID and Col2 is Date

Can you suggest a vectorized approach? For a single-date (outside of matrix), addtodate(d, -3, 'month') works perfectly fine!

役に立ちましたか?

解決

how about this?

newDateVector = arrayfun(@(x) addtodate(x, -3, 'month'), oldDateVector)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top