Problem Importing Text File into TimeTable

1 回表示 (過去 30 日間)
Forrest Ward
Forrest Ward 2020 年 6 月 10 日
編集済み: Eric Sofen 2020 年 7 月 2 日
Hello, so I'm still pretty new to Matlab and I have a problem that I have no idea how to begin to solve. I want to import this text file that I have into a Time Table. However, the dates in the text file are seperated by colons (ex. Date(dd:mm:yyyy), Time(hh:mm:ss) ). I haven't been able to figure out how to tell MATLAB to recognize that the colons represent the day, month, and year. I'll attach my file too, just so you can see the format of it. Any help will do, thanks!

採用された回答

Eric Sofen
Eric Sofen 2020 年 6 月 30 日
編集済み: Eric Sofen 2020 年 7 月 2 日
Because the second variable is uses ":" as a separator, it is being treated as a duration by default. I would recommend using importOptions to specify that it is a datetime and set the format. This should get you something more useful:
opts = detectImportOptions("~/Downloads/ShortTextFile.txt","VariableNamesLine",3);
opts = setvaropts(opts,"Date_dd_mm_yyyy_","Type","datetime","InputFormat","dd:MM:yyyy")
t = readtable("~/Downloads/ShortTextFile.txt",opts);
t.Time = t.Date_dd_mm_yyyy_ + t.Time_hh_mm_ss_;
tt = table2timetable(t,'RowTimes','Time')

その他の回答 (1 件)

Samatha Aleti
Samatha Aleti 2020 年 6 月 15 日
Hi,
The following MATLAB Answer might be of help to you:
  1 件のコメント
Forrest Ward
Forrest Ward 2020 年 6 月 15 日
Thank you for replying, but that link does not really answer my question.

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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by