Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

error while using addtodate in bsxfun

1 visualizzazione (ultimi 30 giorni)
Sergey Gromov
Sergey Gromov il 24 Apr 2014
Chiuso: MATLAB Answer Bot il 20 Ago 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.

Risposte (0)

Questa domanda è chiusa.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by