MATLAB: Trying to extract data from a csv file

.csv fileexcel fileextract columnextract dataimporting excel datamatlab excel

Hello, I'd like to create a data logging system that extracts a certain cell range from an excel file, but I'm running into trouble.
Here is my very simple code:
filename = 'mydata.csv';
M = csvread('mydata.csv',3,4,[3,4,22,4])
Here is the error I am getting:
Error using dlmread (line 147)
Mismatch between file and format string.
Trouble reading 'Numeric' field from file (row number 1,
field number 7) ==> hours instead of 24,\n
Error in csvread (line 50)
m=dlmread(filename, ',', r, c, rng);
Error in Untitled (line 2)
M = csvread('lap shear data.csv',3,4,[3,4,22,4])
Does anyone know why this is happening? I just want to extract the column that has the numbers (Column 5).. Not sure why it's trying to read the next one over.
Thanks in advance!!

Best Answer

Older versions of csvread cannot be used with files with any text, not even in header lines. Somewhere around R2014a it started being able skip text in header lines, and if I recall, also that it could also skip text in row headers (in both cases, it had to be told to skip them.)
However, those newer versions still cannot handle trailing columns of text. You will not be able to read that file format with csvread.
I suggest that you try readtable first. If that does not work then you will need to code a format and use textscan
Related Question