How can I find out some specific dates from two date lists?
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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 个评论
Cris LaPierre
2023-6-8
load DateList1.mat
load DateList2.mat
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')
更多回答(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!