How to filter winter months

조회 수: 3(최근 30일)
Nicky T 2020년 2월 27일
편집: Bhaskar R 2020년 2월 27일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

편집: Bhaskar R 2020년 2월 27일
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)

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Walter Roberson 2020년 2월 27일
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by