remove selected months and years

2 views (last 30 days)
akk
akk on 26 Jul 2019
Edited: Adam Danz on 26 Jul 2019
Hi,
I am trying to create a matrix where I have removed selected months and years. Here is what I have so far:
dv=datevec(date); %where dv(:,1)=year, dv(:,2)=month and dv(:,3)=day
How do I remove summer of 2009 (i.e., dv(:,1)=2009, dv(:,2)=7 and dv(:,2)=8) and create a new dv?
Thanks!

Accepted Answer

Adam Danz
Adam Danz on 26 Jul 2019
Edited: Adam Danz on 26 Jul 2019
idx = dv(:,1) == 2019 & ismember(dv(:,2),[6,7,8]);
dv2 = dv(~idx,:); % to create a new dv
dv(idx,:) = []; % to remove from existing dv
  3 Comments
akk
akk on 26 Jul 2019
Ah yes. I was just about to ask about your answer until you edited it. This makes more sense. Thanks!
Adam Danz
Adam Danz on 26 Jul 2019
Edited: Adam Danz on 26 Jul 2019
Yeah, I switched the last two lines in case they were both run on the same dv vector. Those two lines are two options to choose from.

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!