help using dlmread/csvread please

조회 수: 19 (최근 30일)
Jim O'Doherty
Jim O'Doherty 2013년 3월 15일
댓글: Walter Roberson 2016년 5월 18일
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);"

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by