How do I filter data based on time?

29 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 19 Nov 2015
Edited: Star Strider on 19 Nov 2015
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 Comments
Star Strider
Star Strider on 20 Nov 2015
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!)
Ellyn Gray
Ellyn Gray on 20 Nov 2015
I'm actually a graduate student doing atmospheric science research. We tend to use a lot of aviation data, because there are such long, publicly available records with high spatial resolution. We're all quite grateful to the aviation community for them!
Thank you for your tips about checking out other questions. I will definitely do that.

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!