How to select multilple months in a time series.

2 ビュー (過去 30 日間)
Ojo Olusola
Ojo Olusola 2022 年 1 月 6 日
コメント済み: Ojo Olusola 2022 年 1 月 9 日
f = readtable('Sample data.xlsx')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
f = 166×6 table
Time insitu era5 ncar_ncep merra2 ceres ___________ ______ ______ _________ ______ _____ 01-Mar-2000 101 242.59 145.1 123.7 135.5 01-Apr-2000 117.44 211.69 162.1 113.5 130.5 01-May-2000 126.48 187.73 155.6 121.5 133.9 01-Jun-2000 120.7 133.91 143.1 131.7 123.5 01-Jul-2000 106.31 123.15 132.8 134 103.3 01-Aug-2000 108.62 133.91 135.5 135.7 104.8 01-Sep-2000 114.76 147.34 136.8 139.1 121.9 01-Oct-2000 125.73 182.99 139.9 131.2 140.1 01-Nov-2000 125.48 223.84 141.3 97.5 123.7 01-Dec-2000 111.72 210.65 131.9 89.5 108.5 01-Jan-2001 101.74 222.8 132 92.9 104.2 01-Feb-2001 100.56 233.1 137.1 104 122.3 01-Mar-2001 109 235.42 159.7 107.4 144.6 01-Apr-2001 125.2 196.64 152.1 113.2 130.8 01-May-2001 130.99 168.17 157.5 114.9 137.6 01-Jun-2001 121.22 142.71 143 111.1 114.9
Kindly help me with code to select January, February, March, April, November and December data as dry season months in a different sheet. Select the remaining months data as wet season in another sheet. Thanks.

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 1 月 6 日
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/855600/Sample%20data.xlsx';
f = readtable(filename);
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
[~, m, ~] = ymd(f.Time);
mask = ismember(m, [1:4 11:12]);
dry = f(mask,:);
wet = f(~mask,:);
dry(1:5,:)
ans = 5×6 table
Time insitu era5 ncar_ncep merra2 ceres ___________ ______ ______ _________ ______ _____ 01-Mar-2000 101 242.59 145.1 123.7 135.5 01-Apr-2000 117.44 211.69 162.1 113.5 130.5 01-Nov-2000 125.48 223.84 141.3 97.5 123.7 01-Dec-2000 111.72 210.65 131.9 89.5 108.5 01-Jan-2001 101.74 222.8 132 92.9 104.2
wet(1:5,:)
ans = 5×6 table
Time insitu era5 ncar_ncep merra2 ceres ___________ ______ ______ _________ ______ _____ 01-May-2000 126.48 187.73 155.6 121.5 133.9 01-Jun-2000 120.7 133.91 143.1 131.7 123.5 01-Jul-2000 106.31 123.15 132.8 134 103.3 01-Aug-2000 108.62 133.91 135.5 135.7 104.8 01-Sep-2000 114.76 147.34 136.8 139.1 121.9
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 1 月 6 日
In my experience, people are more likely to want to group by season -- one dry season, one wet season, one dry season, and so on -- instead of wanting to bunch together all wet in one place, and all dry in another.
Ojo Olusola
Ojo Olusola 2022 年 1 月 9 日
The codes worked perfectly. Thanks.

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

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by