How can I index the dates of double data type ?

조회 수: 5 (최근 30일)
Shivam Pande
Shivam Pande 2018년 10월 7일
댓글: Shivam Pande 2018년 10월 13일
I have a column in a table that contains dates from 1-Jan-2013 to 15-Sep-2018 in the following format : 20130101, 20130102,...,20180915. I want assign index to the dates i.e. index=1 to 20130101, index=2 to 20130102 and so on. The dates are in double datatype and not datetime datatype. Can someone tell me how to do this?

채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 7일
Take the third output of unique() as the indices and the first output as the list of what the indices refers to.
You can also look at categorical() but you need to know some implementation details to retrieve the indices.
Depending on what you want to do with the values, you should consider using datetime() on the values and converting the table into a timetable which you would then be able to index by datetime
  댓글 수: 2
Peter Perkins
Peter Perkins 2018년 10월 12일
Just for the record, numbers like that are super easy to convert:
>> datetime([20130101, 20130102, 20180915],'ConvertFrom','yyyymmdd')
ans =
1×3 datetime array
01-Jan-2013 00:00:00 02-Jan-2013 00:00:00 15-Sep-2018 00:00:00
Shivam Pande
Shivam Pande 2018년 10월 13일
Got it. Thanks.

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

추가 답변 (0개)

카테고리

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