How to filter winter months

10 ビュー (過去 30 日間)
Nicky T
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?
I appreciate your help.

採用された回答

Bhaskar R
Bhaskar R 2020 年 2 月 27 日
編集済み: 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
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.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by