Remove rows in a csv file

9 views (last 30 days)
Olle Schälin
Olle Schälin on 28 Aug 2014
Commented: Olle Schälin on 28 Aug 2014
Hello,
Like many others, I have csv file where the first rows (in my case 10 rows) containing text (or are empty), and hence I haven't find a way to figure how to import the file. I have tested other solutions, like (<http://www.mathworks.com/matlabcentral/answers/22710-help-removing-columns-from-csv-file)>, but that didn't solve the problem. When open the csv file in Excel, the beginning looks like this: (It looks very fuzzy, sorry for that).
Model,"WE7000" BlockNumber,"1" TraceName,"CH3","CH4", BlockSize,288154,288154, Date,08/11/25,08/11/25, Time,10:07:43,10:07:43, VUnit,V,V, HResolution,5.000000e-006,5.000000e-006,
block0 -4.999995E+000,-3.230750E+002,-3.685000E+001 -4.999990E+000,-3.230750E+002,-3.685000E+001 -4.999985E+000,3.104250E+002,-3.677500E+002 -4.999980E+000,3.104250E+002,-3.677500E+002 -4.999975E+000,-8.191750E+002,-8.189500E+002

Accepted Answer

Olle Schälin
Olle Schälin on 28 Aug 2014
I have extracted the first 12 rows from the original file into a separate one, and attached that. I hope that will give a view how the the original file looks like.
Previous, I have been succesful with using dlmread with other kind of files (i.e dat), where the first rows have been pure text, i.e using this kind of command:
m=dlmread('Test_20130404_0006.dat','/',13,0); or m=dlmread('Test_20130404_0006.dat','',13,0);
But when I´m doing that with my original csv file I get a quite common error message:
Mismatch between file and format string. Trouble reading number from file (row 2u, field 1u) ==>
  3 Comments
Michael Haderlein
Michael Haderlein on 28 Aug 2014
resp, you have set the wrong delimiter:
>> m=dlmread('Book2.csv',',',10,0)
m =
-5.0000 -323.0750 -36.8500
-5.0000 -323.0750 -36.8500
Olle Schälin
Olle Schälin on 28 Aug 2014
Damn, just too easy. I guess a need to change the resolution of my screen.
Many thanks!

Sign in to comment.

More Answers (1)

Michael Haderlein
Michael Haderlein on 28 Aug 2014
Without line breaks, it's a bit tricky to see how the file is formatted. However, all the text file reading functions have kind of a headerlines functionality (range for dlmread). You can just skip the first 10 rows with that. If you need help to apply such headerlines, please attach a sample file. It makes things easier usually ;-)

Community Treasure Hunt

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

Start Hunting!