フィルターのクリア

How to read row1 as datetime

3 ビュー (過去 30 日間)
Yasuyuki Hamanaka
Yasuyuki Hamanaka 2021 年 5 月 24 日
コメント済み: Yasuyuki Hamanaka 2021 年 5 月 29 日
I read below table using readtable(). I wnat to read first and second column of the first row as string. But after the third clumn, I want to read data as datetime. And other data should be read as double. How can I do that?

採用された回答

Uday Pradhan
Uday Pradhan 2021 年 5 月 27 日
編集済み: Uday Pradhan 2021 年 5 月 27 日
Hi,
To read the first row in the specified format, you could try:
t = readtable('yourDataOnlyRow1','Format','%s %s %{mm/dd/yyyy HH:MM}D %{mm/dd/yyyy HH:MM}D %{mm/dd/yyyy HH:MM}D','TextType','string','ReadVariableNames',false)
where the file yourDataOnlyRow1 contains only the first row of your data. For the rest of the data, you could do:
t1 = readtable('yourData','Format','%f%f%f%f%f','ReadVariableNames',false,'HeaderLines',1) %exclude the first row from the original data file
These two table cannot be joined due to conflicting data types. Perhaps try reformatting your data and have a look at the following documentation pages:table2timetable,readtable.
Note:To get the data as a table with text entries, try:
>> t1 = readtable('yourData.txt','Format','auto')
t1 =
2×5 table
Var1 Var2 Var3 Var4 Var5
____________ ______________ __________________ __________________ __________________
{'Depth ()'} {'Channel ()'} {'4/5/2018 11:10'} {'4/5/2018 12:10'} {'4/5/2018 12:12'}
{'1' } {'2' } {'3' } {'4' } {'5' }
  1 件のコメント
Yasuyuki Hamanaka
Yasuyuki Hamanaka 2021 年 5 月 29 日
Thank you for replying. I used readtable() and read the date as numeric. After that, I reform the data to date using datetime().
During coding, I noticed that using readtable() to read data as datetime is much slower than as numeric data. Is this correct?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by