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

Adam Danz
Adam Danz 2020년 4월 28일
That data you attached does not contain a timetable or any kind of datatime data.

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2020년 4월 28일

1 개 추천

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

Hamed Hedayatnia
Hamed Hedayatnia 2020년 4월 28일
I use this code and get this error:
Unable to use a value of type 'datetime' as an index.
Hamed Hedayatnia
Hamed Hedayatnia 2020년 4월 28일
this is a part of my timetable
Adam Danz
Adam Danz 2020년 4월 28일
편집: Adam Danz 2020년 4월 28일
Could you show me your code and explain the variables in the code? I'm not using datetime as an index so I suspect there is an implementation error.
Hamed Hedayatnia
Hamed Hedayatnia 2020년 4월 28일
I made a timetable:
Data_m = table2timetable(Data,'RowTimes',timeSamples_1);
then change your code to with my table name
isLeapDay = month(Data_m.Time)==2 & day(Data_m.Time)==29;
Data_m(isLeapDay,:) = []; % remove leap days.
after applying i got this error
Hamed Hedayatnia
Hamed Hedayatnia 2020년 4월 28일
isLeapDay = month(TT.Time)==2 & day(TT.Time)==29;
I think this creates an index
Adam Danz
Adam Danz 2020년 4월 28일
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 2020년 4월 28일
Thanks Adam, I applied it in anouther file and it works great.
Adam Danz
Adam Danz 2020년 4월 28일
Sounds like you worked it out! Glad I could help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

질문:

2020년 4월 28일

댓글:

2020년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by