Info

此问题已关闭。 请重新打开它进行编辑或回答。

error while using addtodate in bsxfun

1 次查看(过去 30 天)
Sergey Gromov
Sergey Gromov 2014-4-24
关闭: MATLAB Answer Bot 2021-8-20
Good day everyone. How to create months vector? I found one suggestion:
x=bsxfun(@(Month,Year) datenum(Year,Month,1),(1:12).',1980:2010);
But would you tell, how can I use this trick,if needed months between 08.2004 and 03.2014? Of course I can use
x=bsxfun(@(Month,Year) datenum(Year,Month,1),(1:12).',2004:2014);
and then cut excess months 01-07.2004 and 04-12.2014. But I I tried to do this:
f = datenum('31.03.2014', 'dd.mm.yyyy');
s = datenum('31.08.2004','dd.mm.yyyy');
monthsQ = months(s, f);
datesA = zeros(1, monthsQ+1);
datesA(:) = s;
monthsB = 0:monthsQ;
dd = bsxfun(@(a,b) addtodate(a,b,'month'),datesA', monthsB); % But an error has accrued.
So why addtodate don’t work in bsxfun?
By the way, this code worked correctly:
A = mat2cell(datesA', ones(monthsQ+1,1), 1);
B = mat2cell(monthsB', ones(1, monthsQ+1), 1);
dd = cellfun(@(a,b) addtodate(a,b,'month'), A, B);
Thanks for attention.

回答(0 个)

此问题已关闭。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by