loop for exctracting daily data for january, february, december,
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2022-3-24
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.
采纳的回答
KSSV
2022-3-24
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!