Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

error while using addtodate in bsxfun

1 view (last 30 days)
Sergey Gromov
Sergey Gromov on 24 Apr 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
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.

Answers (0)

This question is closed.

Products

Community Treasure Hunt

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

Start Hunting!