Borrar filtros
Borrar filtros

How to filter winter months

3 visualizaciones (últimos 30 días)
Nicky T
Nicky T el 27 de Feb. de 2020
Editada: Bhaskar R el 27 de Feb. de 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.

Respuesta aceptada

Bhaskar R
Bhaskar R el 27 de Feb. de 2020
Editada: Bhaskar R el 27 de Feb. de 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)

Más respuestas (1)

Walter Roberson
Walter Roberson el 27 de Feb. de 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.


Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by