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

조회 수: 4 (최근 30일)
Muhammad Uswah Pawara
Muhammad Uswah Pawara 2022년 3월 24일
댓글: Stephen23 2022년 3월 24일
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
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 = 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.

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by