How do I filter data based on time?
20 ビュー (過去 30 日間)
古いコメントを表示
I have decades of hourly meteorological data that I want to investigate for the months October-April every year (essentially a long winter). I figured out how to filter only those dates, but I also want to filter the data itself for those dates. At this point, I have a shortened dateArray, but my other variables are still the entire year. How do I associate the variables with a particular time?
I tried using the timeseries class, but it did not like that I was using datetime. Also, the timeseries class does not have "month," which would make it difficult for me to filter by season.
date1 = dataArray{:, 1};
windDir = dataArray{:, 2};
windSpeed = dataArray{:, 3};
ceilingHeight = dataArray{:, 4};
visibility = dataArray{:, 5};
temp = dataArray{:, 6};
dewpoint = dataArray{:, 7};
SLP = dataArray{:, 8};
formatIn = 'yyyymmddHHMM';
dateArray = datetime(datevec(num2str(date1),formatIn),'InputFormat','yyyymmddHHMMSS','TimeZone','America/Los_Angeles','Format','d-MMM-y HH:mm:ss Z');
%converted my numerical date to a string to use datevec to break it up into 6 vectors to be read in by datetime
dateMonth = month(dateArray);
%identify month to filter by season
dateSpring=(dateArray(dateMonth <=4));
%create a variable that is all the dates for Jan-April
dateFall=(dateArray(dateMonth >=10));
%create a variable that is all the dates for Oct-Dec
dateWinter=union(dateSpring,dateFall);
%combine Jan-April and Oct-Dec
0 件のコメント
採用された回答
Star Strider
2015 年 11 月 19 日
編集済み: Star Strider
2015 年 11 月 19 日
Without your data, it’s not possible to write specific code. You need the row numbers that correspond to your chosen dates. One approach that I would use first is the ismember function. If all goes well, the ‘RowIdx’ vector will have the row indices of your chosen dates, and you can use them to select your other data.
Hypothetical code:
Lia = ismember(dateArray, date1);
RowIdx = find(Lia);
This is obviously UNTESTED CODE. I’m assuming that the dates in ‘dateArray’ have the same format as those in ‘date1’. They have to have the same format in order for this approach to work.
7 件のコメント
Star Strider
2015 年 11 月 20 日
My pleasure!
You’re always welcome to share your expertise here. We were all newbies once, and I learned much by reading other Answers and solving interesting problems here that I might not otherwise have encountered in my own research areas.
I notice your data are from Redding Municipal Airport. I never flew into there myself, so I’m curious to know if you’re also a Private Pilot, since a lot of the information you’re analysing is of interest principally to pilots. (I’m ASEL/IRA here!)
その他の回答 (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!