MATLAB Answers


how to read CSV file in matlab while ignoring the first line

Asked by Kobi
on 23 Sep 2014
Latest activity Commented on by Image Analyst
on 24 Sep 2014
hi i have this csv file with one header that i dont need and two columns of numbser that i need: i tried textscan but for some reason it wont work correctly
dat=textscan(fid,'%f%f%f%f%f','Headerlines',1 );
what is wrong?

  1 Comment

Attach your file here instead. Use the ‘paperclip’ or ‘staple’ icon. (Your file doesn’t exist at the URL you supplied.)

Sign in to comment.


2 Answers

Answer by dpb
on 24 Sep 2014

What is wrong is you didn't specify the delimiter...
For a simple file such as this, while TMW has relegated it to red-haired stepchild status, I still prefer textread as it returns an array directly instead of a cell array when it isn't (necessarily) needed and handles the filename inherently saving the bother of the fopen/fclose pair...
I used a single format string and reshape as the one peculiarity for textread for the purpose of returning a single array is that it expects as many output variables as there are conversion fields in the format string.


Sign in to comment.

Answer by Image Analyst
on 24 Sep 2014

You might want to look at importdata(). You can specify delimiter and number of headerlines to skip.

  1 Comment

I think it's like textscan() except it does the opening and closing for you.

Sign in to comment.