Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

error while using addtodate in bsxfun

1 vue (au cours des 30 derniers jours)
Sergey Gromov
Sergey Gromov le 24 Avr 2014
Clôturé : MATLAB Answer Bot le 20 Août 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.

Réponses (0)

Cette question est clôturée.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by