How to concatenate (take cross product of) two datetime arrays?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have two arrays
Date = [datetime(2016,4,5), datetime(2016,5,4), datetime(2016,6,7)];
Time = duration(0,0:30:90,0,'Format', 'hh:mm:ss');
I want a product of these two arrays such that result is
ans =
5-Apr-2016 00:00:00
5-Apr-2016 00:30:00
5-Apr-2016 01:00:00
5-Apr-2016 01:30:00
4-May-2016 00:00:00
4-May-2016 00:30:00
4-May-2016 01:00:00
...
0 Commenti
Risposte (2)
Andrei Bobrov
il 19 Lug 2016
Date = [datenum(2016,4,5), datenum(2016,5,4), datenum(2016,6,7)];
a = bsxfun(@plus,Date,1/48*(0:3)');
out = datestr(a,'dd-mmm-yyyy HH:MM:SS');
0 Commenti
Guillaume
il 19 Lug 2016
Modificato: Guillaume
il 19 Lug 2016
This avoids conversion to datenum:
Date = [datetime(2016,4,5), datetime(2016,5,4), datetime(2016,6,7)];
Time = duration(0,0:30:90,0,'Format', 'hh:mm:ss');
[tidx, didx] = ndgrid(1:numel(Time), 1:numel(Date));
result = reshape(Date(didx) + Time(tidx), [], 1)
0 Commenti
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!