필터 지우기
필터 지우기

How can I take out months rows from each year.

조회 수: 2 (최근 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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by