loop for exctracting daily data for january, february, december,
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad Uswah Pawara
el 24 de Mzo. de 2022
Comentada: Stephen23
el 24 de Mzo. de 2022
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 comentario
Stephen23
el 24 de Mzo. de 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.Month % easiest and most efficient
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.
Respuesta aceptada
KSSV
el 24 de Mzo. de 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
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!