필터 지우기
필터 지우기

Cannot I import data from a file with multiples delimiters?

조회 수: 19 (최근 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

댓글을 달려면 로그인하십시오.

카테고리

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