Cannot I import data from a file with multiples delimiters?

18 ビュー (過去 30 日間)
Javier
Javier 2017 年 7 月 6 日
コメント済み: Star Strider 2017 年 7 月 7 日
Hello,
I have a file called a.txt which has the following format
{"node_id":"a4","Arrived at":"2017-07-04T02:57:06.344971Z","total_Light":66.7959976196289,"S1":0,"S2":0,"S3":0}
{"node_id":"a2","Arrived at":"2017-07-04T02:57:06.344971Z","total_Light":66.7959976196289,"S1":0,"S2":0,"S3":0}
...
I would like to import that data as is being done with the gui import data in Matlab but from the command line, I have searched for importdata however I get an error in such a function saying that it cannot handle multidelimeters, even when the help makes you believe so.
If I invoke the importata over my file a.txt like this,
d = importdata('a.txt',[':',',','}'],1)
I get this error
Error using importdata (line 225)
Unable to load file.
Use TEXTSCAN or FREAD for more complex formats.
Caused by:
Error using importdata>parse (line 309)
Multicharacter delimiters are not supported.
Is it possibe to use importdata to with the multidelimeters or I have to turn to textscan?
Thanks in advance

採用された回答

Javier
Javier 2017 年 7 月 7 日
The solution for me was using the function readtable that it does allow as well the use of several delimeters
delimeters = {',','}',':'};
d = readtable('a.txt','Delimiter',delimeters)
d =
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13
____________ _____ ____________ _____________________________ _____________ ______ ____ ____ ____ _____ _____ _____ _____
'{"node_id"' 'a3' 'Arrived at' '2017-07-03T14:41:58.931247Z' 'total_Light' 7273.4 'S1' 253 'S2' 534 'S3' 64 NaN
'{"node_id"' 'a3' 'Arrived at' '2017-07-03T14:42:40.290891Z' 'total_Light' 7231.6 'S1' 259 'S2' 519 'S3' 61 NaN

その他の回答 (1 件)

Star Strider
Star Strider 2017 年 7 月 6 日
The textscan (link) function allows you to specify multiple delimeters. See the section on 'Delimiter' (link) for details.
  2 件のコメント
Javier
Javier 2017 年 7 月 7 日
Thanks Star Strider, in the end I have used readtable() since my data is almost table formated and it does also allow the use of several delimeters as textscan
Star Strider
Star Strider 2017 年 7 月 7 日
My pleasure.

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

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by