Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

error while using addtodate in bsxfun

1 visualización (últimos 30 días)
Sergey Gromov
Sergey Gromov el 24 de Abr. de 2014
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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.

Respuestas (0)

La pregunta está cerrada.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by