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

조회 수: 116 (최근 30일)
Kobi
Kobi 2014년 9월 23일
댓글: Image Analyst 2014년 9월 24일
hi i have this csv file with one header that i dont need and two columns of numbser that i need: https://www.dropbox.com/s/oq2zgmosna347e5/004cm.csv?dl=0 i tried textscan but for some reason it wont work correctly
fid=fopen('004cm.csv');
dat=textscan(fid,'%f%f%f%f%f','Headerlines',1 );
fclose(fid);
what is wrong?
  댓글 수: 1
Star Strider
Star Strider 2014년 9월 24일
Attach your file here instead. Use the ‘paperclip’ or ‘staple’ icon. (Your file doesn’t exist at the URL you supplied.)

댓글을 달려면 로그인하십시오.

답변 (2개)

dpb
dpb 2014년 9월 24일
What is wrong is you didn't specify the delimiter...
dat=textscan(fid,'%f%f%f%f%f','Headerlines',1,'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...
dat=reshape(textread('matt.csv','%f','delimiter',',','headerlines',1),5,[]).'
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.

Image Analyst
Image Analyst 2014년 9월 24일
You might want to look at importdata(). You can specify delimiter and number of headerlines to skip.
  댓글 수: 1
Image Analyst
Image Analyst 2014년 9월 24일
I think it's like textscan() except it does the opening and closing for you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by