Pulling a specific element out of a cell?

4 ビュー (過去 30 日間)
Grace
Grace 2019 年 5 月 8 日
編集済み: Adam Danz 2019 年 5 月 9 日
I have imported a file into my script which included a header. I was able to pull a specific line from my header that reads: ";Start_time, 2007-01-01, 00:48:23.729". This is now a 1x1 cell. I want to be able to indicate and use the date and time stamps separatly. How do I do this?

採用された回答

Adam Danz
Adam Danz 2019 年 5 月 8 日
編集済み: Adam Danz 2019 年 5 月 9 日
To convert an array of file names to datetime
d = {
';Start_time, 2007-01-01, 00:48:23.729'
';Start_time, 2007-02-01, 00:48:23.729'
';Start_time, 2007-03-01, 00:48:23.729'
';Start_time, 2007-04-01, 00:48:23.729'
';Start_time, 2007-05-01, 00:48:23.729'
';Start_time, 2007-06-01, 00:48:23.729'};
% Remove stuff at beginning
d = strrep(d, ';Start_time, ', '');
% convert to datetime (use 'Format' property to specify format of output)
dates = datetime(d,'InputFormat','yyyy-MM-dd, hh:mm:ss.S');
% RESULT:
6×1 datetime array
01-Jan-2007 00:48:23
01-Feb-2007 00:48:23
01-Mar-2007 00:48:23
01-Apr-2007 00:48:23
01-May-2007 00:48:23
01-Jun-2007 00:48:23
  2 件のコメント
Grace
Grace 2019 年 5 月 9 日
What if I have a bunch of similar files being flipped thrpugh in a for loop and I want it to extract each of the start times and have them returned as a vector?
Adam Danz
Adam Danz 2019 年 5 月 9 日
編集済み: Adam Danz 2019 年 5 月 9 日
I just updated my anser to address that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by