loop for exctracting daily data for january, february, december,
4 views (last 30 days)
Show older comments
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 Comment
Stephen23
on 24 Mar 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.
Accepted Answer
KSSV
on 24 Mar 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 Comments
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!