help using dlmread/csvread please

16 次查看(过去 30 天)
All,
I thought this would be an easy one but after 45 minutes of trying I can't seem to read in my .csv file. I've been trying to use dlmread as most of the file is non-numeric (and csvread seems to just dlmread anyway)
Heres a section of the file (each column has 14 entries):
Protocol ID,Protocol name,Measurement date & time,Completion status,Run ID,Rack,Det,Pos,Time,Sample code,F-18 Counts,F-18 CPM,F-18 Error %,F-18 Info
19,18F-any,15/03/2013 14:02,0,164,1,1,1,180.05,,10613633.53,5364219.76,0.04,
19,18F-any,15/03/2013 14:02,0,164,1,2,2,180.05,,10743127.87,5508950.9,0.04,
19,18F-any,15/03/2013 14:02,0,164,1,3,3,180.05,,3868341.08,1354963.52,0.08,
19,18F-any,15/03/2013 14:02,0,164,1,4,4,180.05,,10987871.62,5439457.84,0.04,R
19,18F-any,15/03/2013 14:02,0,164,1,5,5,180.05,,6897896.87,3352857.77,0.05,
If I want the contents of the 3rd row, 4th column (zero-based), I type
val = dlmread('000164.csv', ',', 2, 5);
and the error I receive is
Error using dlmread (line 139)
Mismatch between file and format string.
Trouble reading number from file (row 3u, field 14u) ==> R\n
I'm basically looking for only 1 column from this file, but I've got hundreds of these files so I'd like to automate it
Any help greatly appreciated!
Jim

采纳的回答

Walter Roberson
Walter Roberson 2013-3-15
dlmread() and csvread() are designed to only expect numeric values, even for columns you are not asking to be returned. You should use textscan()
  3 个评论
Iain
Iain 2016-5-18
I understand that csv/dlmread are designed for numeric values. But it makes absolutely no sense that I can use R1 to skip text filled header lines but I cannot use C2 to skip text filled columns? I don't understand why is Matlab reading beyond C2, I'm not a computer scientist but it seems very inefficient (e.g. if I had 100,000 columns but only needed to parse 3 of them)?
Walter Roberson
Walter Roberson 2016-5-18
If you are using R2015b or later (maybe R2015a, I am not sure) then csvread() can skip leading text columns, apparently. It is not well documented.
If you want to ignore to end of line then you can use textscan with a format element of %*[^\n]

请先登录,再进行评论。

更多回答(1 个)

durga ganesan
durga ganesan 2016-2-21
i run my matlab code show this error so how i solve this "Error using textscan Mismatch between file and format string. Trouble reading floating point number from file (row 10u, field 2u) ==> ';\n
Error in park (line 51) dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false);"

Community Treasure Hunt

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

Start Hunting!

Translated by