cell to string to date time

I am importing a time from a .txt file. The import was auto-generated by matlab. The timestamp array is in this form: '2015-08-07 13:12:00' The variable is a 100x1 cell...I am not sure how to get the cell to a usable date time. Thank you.
...I can also import from the auto-generated import, however the import format does not match any of the available formats.

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 8 月 16 日

1 投票

datenum(TheCell)
to return the older serial datenum objects.
datetime(TheCell)
to return the newer datetime objects.
Peter Perkins
Peter Perkins 2015 年 8 月 18 日

0 投票

Samantha, it sounds like you have code that you generated using the Import Tool. When you import a text file using the IT, you can specify that a particular column is datetime strings, and even specify a custom format for the strings. I cooked up a file with one column of numbers and one column of datetime strings, and the code I generated contains a line like
formatSpec = '%f%{yyyy-MM-dd HH:mm:ss}D%[^\n\r]';
That script/function will import that column as a datetime array. It's not clear if that's what you're looking to do.

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

質問済み:

2015 年 8 月 16 日

回答済み:

2015 年 8 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by