MATLAB Answers

Removing Leap day from my timetable

4 views (last 30 days)
Hamed Hedayatnia
Hamed Hedayatnia on 28 Apr 2020
Commented: Adam Danz on 28 Apr 2020
I need to remove leap days of all years from my timetable. I mean all values belong to 29 feb. my timetable is a hourly time table.

  1 Comment

Adam Danz
Adam Danz on 28 Apr 2020
That data you attached does not contain a timetable or any kind of datatime data.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 28 Apr 2020
TT is the timetable and TT.Time is the time column.
isLeapDay is a logical vector identiying the rows of TT that belong to a leap day.
isLeapDay = month(TT.Time)==2 & day(TT.Time)==29;
TT(isLeapDay,:) = []; % remove leap days.

  8 Comments

Show 5 older comments
Adam Danz
Adam Danz on 28 Apr 2020
Yes, that creates an index; not a datetime vector. The error message you shared "Unable to use a value of type 'datetime' as an index." indicates that the error is caused by something else.
I just applied the answer to the data you shared and it works without error.
Please provide the full copy-pasted error message and include the line of code that the error message points to. The error message is not associated with the code from my answer.
Also, what version of Matlab are you using?
Hamed Hedayatnia
Hamed Hedayatnia on 28 Apr 2020
Thanks Adam, I applied it in anouther file and it works great.
Adam Danz
Adam Danz on 28 Apr 2020
Sounds like you worked it out! Glad I could help.

Sign in to comment.

More Answers (0)


Translated by