How do I filter data based on time?
Show older comments
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
More Answers (0)
Categories
Find more on Logical 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!