How to filter winter months

2 views (last 30 days)
Nicky T
Nicky T on 27 Feb 2020
Edited: Bhaskar R on 27 Feb 2020
Hi there,
I am trying to filter the winter months in my data. I use the command below:
time = time (month(time) >= 1 & month(time) <= 4 & month(time)>9 & month(time)<=12) ;
It does not work. Does anyone know the answer?
I appreciate your help.

Accepted Answer

Bhaskar R
Bhaskar R on 27 Feb 2020
Edited: Bhaskar R on 27 Feb 2020
Do you mean to get the time values between 1 to 4 and 10 to 12 (winter )? if yes
x = 1:12;
data = x(x >= 1 & x <= 4 | x>9 & x<=12)

More Answers (1)

Walter Roberson
Walter Roberson on 27 Feb 2020
There does not exist a number that is simultaneously at most 4 but at the same time also greater than 9. & is only satisfied if all the parts are satisfied.
You want a test that checks whether something is true OR something else is true.
However I would suggest that you consider using a different method. In particular read about ismember()
Or you could have a single logical vector that you index by the month number.
I notice that the local definition of "winter" where I live is slightly different. Your code would call October a winter month. Where I live, October is not considered a winter month: it is considered an autumn month. One kind of wheat is harvested, and many pumpkins might be harvested, but the rest of the harvest is September or even August for many greens. October is just sort of in-between. Overcast and rain, temperatures fluctuating above and below freezing. November is mostly below freezing here but "winter" is not quite considered to have started here until the last week of November when we get a heavy snow.
The point is that you need to reconsider what "winter" means in context. Like only 100 miles south of us, "winter" is about a month later than for us.

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!