Filter löschen
Filter löschen

loop for exctracting daily data for january, february, december,

1 Ansicht (letzte 30 Tage)
I have 3 dimensional data (10x10x25933), it is hourly data from 1950-1-1 to 2020-12-31. how to make a loop to extract daily data for January, February, and december.
Here is my code for 1 grid point;
t1=(datetime(1950,1,1):hours(24):datetime(2020,12,31))';
t1.Format = 'yyyy-MM-dd hh:mm:ss';
TT=timetable(t1,T);
RT = ismember(month(TT.t1),[1,2,12]);
TTT = TT(RT,:);
Tdjf=TTT.T(TTT.t1);
File link
https://drive.google.com/file/d/1YrF2aKAxp7mym5fXJyctQW44058pfBtE/view?usp=sharing
  1 Kommentar
Stephen23
Stephen23 am 24 Mär. 2022
Your original approach was much better than using deprecated date functions. Do NOT use DATEVEC.
DT = datetime(1950,1,1):caldays(1):datetime(2020,12,31);
DT = DT(:)
DT = 25933×1 datetime array
01-Jan-1950 02-Jan-1950 03-Jan-1950 04-Jan-1950 05-Jan-1950 06-Jan-1950 07-Jan-1950 08-Jan-1950 09-Jan-1950 10-Jan-1950 11-Jan-1950 12-Jan-1950 13-Jan-1950 14-Jan-1950 15-Jan-1950 16-Jan-1950 17-Jan-1950 18-Jan-1950 19-Jan-1950 20-Jan-1950 21-Jan-1950 22-Jan-1950 23-Jan-1950 24-Jan-1950 25-Jan-1950 26-Jan-1950 27-Jan-1950 28-Jan-1950 29-Jan-1950 30-Jan-1950
DT.Month % easiest and most efficient
ans = 25933×1
1 1 1 1 1 1 1 1 1 1
for example:
idx = ismember(DT.Month,[1,2,12]);
It is not clear from your question if you expect to get three groups (one for each of the requested months), or one group containing all of the data for all of the requested months. Please clarify.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 24 Mär. 2022
t1=(datetime(1950,1,1):hours(24):datetime(2020,12,31))';
t1.Format = 'yyyy-MM-dd hh:mm:ss';
[y,m,d,H,M,S] = datevec(t1) ; % this will give year, monthm day, hour, minute, second
% extract january
idx = m==1 ; % Jan is month = 1
iwant = data(:,:,idx) ; % where data is your 10x10x25933 matrix

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by