Cannot I import data from a file with multiples delimiters?

18 次查看(过去 30 天)
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Large 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