How can I take out months rows from each year.

1 回表示 (過去 30 日間)
Megan Mirkhanian
Megan Mirkhanian 2020 年 2 月 9 日
編集済み: Megan Mirkhanian 2020 年 2 月 10 日
g

回答 (2 件)

Hiro Yoshino
Hiro Yoshino 2020 年 2 月 10 日
d = ['190101'; '190201'; '190301']; % sample data
d_datetime = datetime(d, 'InputFormat', 'yyMMdd'); % change format to datetime
[y,m,d] = ymd(d_datetime); % break it into pieces
idx = m == 1 | m == 2; % extract the indices corresponding to Jan and Feb. You can add " | m == 12 " to extract December!
Please take a look at this. I belive this is applicable to your problem.
  2 件のコメント
Image Analyst
Image Analyst 2020 年 2 月 10 日
Then
yourTable = yourTable(~idx, :); % Extract all rows EXCEPT rows identified by idx.
Megan Mirkhanian
Megan Mirkhanian 2020 年 2 月 10 日
I am trying to get all the data to run in line 4 but it shoes an error

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


Hiro Yoshino
Hiro Yoshino 2020 年 2 月 10 日
編集済み: Hiro Yoshino 2020 年 2 月 10 日
I guess your date is not read as string.
tableData = readtable('yourExcel.xlsx');
tableData.Time = string(tableData.Time);
Then you can start from
d_datetime = datetime(tableData.Time, 'InputFormat', 'yyMMdd'); % change format to datetime
  2 件のコメント
Megan Mirkhanian
Megan Mirkhanian 2020 年 2 月 10 日
So I need the precipitation data for the month, so when I run it, it only shows month numbers, ex: it shows 1,1,1,1,1,1 then 2,2,2,2 and no info on precip. Sorry, if this all sounds confusing.
Hiro Yoshino
Hiro Yoshino 2020 年 2 月 10 日
[y,m,d] = ymd(d_datetime); % break it into pieces
idx = m == 1 | m == 2; % extract the indices corresponding to Jan
Do not forget these lines!! Good luck! almost there.

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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by