# How can I find out some specific dates from two date lists?

조회 수: 1 (최근 30일)
Ashfaq Ahmed 2023년 6월 8일
댓글: Ashfaq Ahmed 2023년 6월 8일
Hi, I have two date lists. DateList1.m contains dates from 1984 to 2022 (with many gaps) and DateList2.m constains dates from 2005 to 2019 (with no gap). I want to make a table that contains all temperature data between 9:00 am to 11:00 am from DateList2.m but those specific dates need to be in dateList1.m as well.
Can anyone please suggest how to code this problem? Any feedback will be much appreciated!

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

### 채택된 답변

Cris LaPierre 2023년 6월 8일
You have date information in DateList1, and date+time information in DateList2.
I would add a column to DateList2 that is just the date. You might find the dateshift function helpful for this. Then I could use ismember to find which dates in DateList2 are in DateList1. At the sime time, you could check that the day time is between 9 and 11 am. Use the hour function with the corresponding relational operators.
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
Cris LaPierre 2023년 6월 8일
I would use groupsummary with your groupbins set to 'day' and method set to 'mean'.
DateList2.date = dateshift(DateList2.Time, 'start', 'day');
% Find days that in DateList2 that are also in DateList1
ind = ismember(DateList2.date,DateList1.date) ...
& hour(DateList2.Time) >= 9 ...
& hour(DateList2.Time) < 11;
T = DateList2(ind,:);
dayAvg = groupsummary(T,"Time",'day','mean','Var1')
dayAvg = 376×3 table
day_Time GroupCount mean_Var1 ___________ __________ _________ 20-Jan-2005 8 2.7238 28-Jan-2005 8 -0.255 05-Feb-2005 8 0.8275 13-Feb-2005 8 1.84 09-Mar-2005 8 1.9125 17-Mar-2005 8 2.005 10-Apr-2005 8 6.9125 18-Apr-2005 8 8.62 26-Apr-2005 8 7.905 12-May-2005 8 10.325 28-May-2005 8 10.974 05-Jun-2005 8 14.269 15-Jul-2005 8 19.61 23-Jul-2005 8 20.246 08-Aug-2005 8 21.062 16-Aug-2005 8 23.195
Ashfaq Ahmed 2023년 6월 8일
Thank you so much. You really know tons of functions!!

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

### 카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by