Read data from complex *csv file
古いコメントを表示
Hello everyone! I've been trying to read data from a .csv file that looks like:
[[0.714792626301598, -0.697224229221414, 0.05431275698645074], 0, 0, 'pos_0'],[[-0.5884201907614969, 0.7739447885416152, -0.23403235544146034], 1, 0, 'pos_1'],[[0.1944985746440766, -0.9746176263199874, 0.11086382154614778], 50, (0, 2), 'pos_4']....
The idea is to get separately for each column:
[0.714792626301598, -0.697224229221414, 0.05431275698645074]
0
0 %this could be in a (0, 2) format as displayed in the third column
'pos_0'
The file is around 200 columns, I've tried the following code:
S = textscan(fid,'%*c %[^] %*c %f %*c %f %s]','Delimiter',',');
resulting in a badly ordered cell array. Any help will be much appreciated!!
Thanks!
3 件のコメント
@Pablo: do not give us screenshots of data: we cannot import screenshots of data, we cannot test code on screenshots of data, we cannot search screenshots of data, we cannot edit screenshots of data, we cannot use screenshots of data in any meaningful way.
Please upload the actual text data file (or a file that represents all of its salient features).
Pablo
2018 年 11 月 2 日
Ugh, what a badly formatted "CSV" file: it is a liberal mess of double quotes, square brackets, and superfluous single quotes... there are random parentheses around two fields, double quotes surround the entirety of each "line", and there is only one newline at the very end of the file! It should be named "Incoherence_disorder.txt".
The best solution to your problem is fix the thing that created that awful file.
採用された回答
その他の回答 (1 件)
madhan ravi
2018 年 11 月 2 日
編集済み: madhan ravi
2018 年 11 月 2 日
fid=fopen('coherence_order.csv','r')
f = textscan(fid,'%s','delimiter',{']'})
fclose(fid)
7 件のコメント
KSSV
2018 年 11 月 2 日
f = textscan(fid,'%s','delimiter','\n')
This takes data as it is in the file. But the user wants all three columns separated.
madhan ravi
2018 年 11 月 2 日
編集済み: madhan ravi
2018 年 11 月 2 日
This takes data as it is in the file
No it doesn’t, instead it reads all of them as separate cells
But the user wants all three columns separated.
True
Pablo
2018 年 11 月 2 日
KSSV
2018 年 11 月 2 日
{'[[0.714792626301598, -0.697224229221414, 0.05431275698645074], 0, 0, 'pos_0'],' }
{'[[-0.5884201907614969, 0.7739447885416152, -0.23403235544146034], 1, 0, 'pos_1'],' }
{'[[0.1944985746440766, -0.9746176263199874, 0.11086382154614778], 50, (0, 2), 'pos_4'],'}
The above is the result of:
f = textscan(fid,'%s','delimiter','\n')
It text scans the file as it is present in the file.
madhan ravi
2018 年 11 月 2 日
did you try this?
f = textscan(fid,'%s','delimiter',{']'})
KSSV
2018 年 11 月 2 日
{'[[0.714792626301598, -0.697224229221414, 0.05431275698645074' }
{', 0, 0, 'pos_0'' }
{',' }
{'[[-0.5884201907614969, 0.7739447885416152, -0.23403235544146034'}
{', 1, 0, 'pos_1'' }
{',' }
{'[[0.1944985746440766, -0.9746176263199874, 0.11086382154614778' }
{', 50, (0, 2), 'pos_4'' }
{','
madhan ravi
2018 年 11 月 2 日
編集済み: madhan ravi
2018 年 11 月 2 日
It is not the expected solution however because of the file arrangement
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!