Probelm importing csv file with csvread
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to import a csv file to my matlab code but something seems to go wrong with the way I am trying to do it. The command that I type is
M = csvread('reoprt_data1.csv',7,1);
Because I want to import a specific range of measurements to a matrix and I get the following answer:
Error using dlmread (line 139) Mismatch between file and format string. Trouble reading number from file (row 1u, field 77u) ==> nity,,0.0,0.0,3.337845264468342E-4,,50.0,0.0,3.337845264468342E-4,,0.0,-3.337845264468342E-4,,0.0,-0.0,148.73287963867188,,0.0,-148.73287963867188,,0.0,Infinity,,\n
Error in csvread (line 48) m=dlmread(filename, ',', r, c);
Error in test (line 6) M = csvread('reoprt_data2.csv',7,1);
Can you please give me some help on that?
Thank you in advance.
0 个评论
回答(3 个)
Image Analyst
2014-6-19
You forgot to attach your csv file. It looks like there are double commas and strings in there. I don't think it can handle that. Try fixing your file. You can call readtable() if you have strings and numbers on the same line.
0 个评论
dpb
2014-6-19
(row 1u, field 77u) ==> nity,,0.0,0.0,3.33...42E-4,,50.0,0.0,...0.0,Infinity,,\n
The recognized value is 'Inf', not 'Infinity'
Your choice is to either create the file with the corrected indicator value or you can try and see if textscan can manage with the 'treatasempty' field altho I've not tested.
Other than that, will have to read as text and parse each line; the way I'd do it would be to read the entire file as a cell array of strings and do a global substitution of 'Inf' for 'infinity' then use read from the memory array w/ sscanf()
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!