taking input from csv file using texstcan

here the content of test.csv file:
Index,Arrival_Time,Creation_Time,x,y,z,User,Model,Device,gt
0,1424696633908,1424696631913248572,-5.958191,0.6880646,8.135345,a,check4,check4_1,home
1,1424696633909,1424696631918283972,-5.95224,0.6702118,8.136536,a,check4,check4_1,home
2,1424696633918,1424696631923288855,-5.9950867,0.6535491999999999,8.204376,a,check4,check4_1,home
3,1424696633919,1424696631928385290,-5.9427185,0.6761626999999999,8.128204,a,check4,check4_1,home
4,1424696633929,1424696631933420691,-5.991516000000001,0.64164734,8.135345,a,check4,check4_1,home
5,1424696633929,1424696631938456091,-5.965332,0.6297455,8.128204,a,check4,check4_1,home
6,1424696633938,1424696631943522009,-5.991516000000001,0.6356963999999999,8.16272,a,check4,check4_1,home
7,1424696633939,1424696631948496374,-5.915344,0.63093567,8.105591,a,check4,check4_1,home
8,1424696633951,1424696631953592810,-5.984375,0.6940155,8.067505,a,check4,check4_1,home
here is the code for getting the data into matrix:
fid = fopen('test.csv');
[data] = textscan(fid, ['%d %llu %llu %lf %lf %lf %s %s %s %s' '%*[^\n]'], 'delimiter', ',','CollectOutput',true);
fclose(fid);
its producing textscan Badly formed format string. As a newbee i am not able to find any solution. anyone help please??

Answers (2)

you have a few longer than 15 digits fields that mislead IMTool.
After adding some Returns, with IMTool i got this;
Try tweaking a few fields:
After removing all the '9' but one on the left, and zeroing the 0000001 IMTool imports data correctly
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
John

2 Comments

hello john..thanks...bt still i cant get the error solved..

after correction test.csv :

Index,Arrival_Time,Creation_Time,x,y,z,User,Model,Device,gt 0,1424696633908,1424696631913248572,-5.958191,0.6880646,8.135345,a,nexus4,nexus4_1,stand 1,1424696633909,1424696631918283972,-5.95224,0.6702118,8.136536,a,nexus4,nexus4_1,stand 2,1424696633918,1424696631923288855,-5.9950867,0.65354919,8.204376,a,nexus4,nexus4_1,stand 3,1424696633919,1424696631928385290,-5.9427185,0.67616269,8.128204,a,nexus4,nexus4_1,stand 4,1424696633929,1424696631933420691,-5.991516,0.64164734,8.135345,a,nexus4,nexus4_1,stand 5,1424696633929,1424696631938456091,-5.965332,0.6297455,8.128204,a,nexus4,nexus4_1,stand 6,1424696633938,1424696631943522009,-5.991516,0.63569639,8.16272,a,nexus4,nexus4_1,stand 7,1424696633939,1424696631948496374,-5.915344,0.63093567,8.105591,a,nexus4,nexus4_1,stand 8,1424696633951,1424696631953592810,-5.984375,0.6940155,8.067505,a,nexus4,nexus4_1,stand

here is the code for getting the data into matrix:

fid = fopen('test.csv'); [data] = textscan(fid, ['%d %llu %llu %lf %lf %lf %s %s %s %s' '%*[^\n]'], 'delimiter', ',','CollectOutput',true,'HeaderLines',1); fclose(fid);

it still shows same error..:(

the following does not crash
[data] = textscan(fid, ['%d %u %u %f %f %f %s %s %s %s %s %s'],'delimiter', ',','CollectOutput',true,'HeaderLines',1);

Sign in to comment.

textscan does not permit the 'l' modifier. It uses numeric suffixes, such as %u32 . See http://www.mathworks.com/help/matlab/ref/textscan.html#inputarg_formatSpec

Categories

Asked:

on 2 Apr 2016

Answered:

on 17 Apr 2016

Community Treasure Hunt

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

Start Hunting!