Cannot I import data from a file with multiples delimiters?

16 views (last 30 days)
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

Accepted Answer

Javier
Javier on 7 Jul 2017
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

More Answers (1)

Star Strider
Star Strider on 6 Jul 2017
The textscan (link) function allows you to specify multiple delimeters. See the section on 'Delimiter' (link) for details.
  2 Comments
Javier
Javier on 7 Jul 2017
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

Sign in to comment.

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!