How to get the indices based on month and year?

5 ビュー (過去 30 日間)
Shayma Al Ali
Shayma Al Ali 2023 年 4 月 3 日
コメント済み: Stephen23 2023 年 4 月 3 日
I have an array of data, "B", with a corresponding datetime array. The data spans between 2018-2022 but its not uniformly distanced so some months have more data than others. My plan is to loop through the data, get the data that corresponds to a month and year (ex. Jan 2020) and run some functions, and then get the data that corresponds to the next month and year, and repeat.
Is there any way I can do it more efficiently? Any functions where I can categorize the data by month and year?

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 4 月 3 日
You can use timerange
But if you want to group by month, then typically it is easier to do something like take
[y, m] = ymd(DATETIMES);
G = findgroups(y, m);
Now you can use G together with splitapply
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 4 月 3 日
Also, you should check to see if using retime could be used for your situation.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by