Data extraction from CSV file

I have numerous csv files generated from various tests that I have conducted. The issue is that these csv files contain strings as well as numbers. I want to extract an entire column from this file.
I have looked at several solutions but nothing seems to work and also I am new to MATLAB. So can someone kindly take a look at it.

답변 (3개)

Sean de Wolski
Sean de Wolski 2012년 12월 4일

0 개 추천

Are you using R2012b?
If so - use the Import Wizard. Click "Import Data" on the home tab and if the *.csv file has any structure, it will parse it for you.

댓글 수: 4

Chandan
Chandan 2012년 12월 4일
Nope, I am using 2012a version
Sean de Wolski
Sean de Wolski 2012년 12월 4일
If your company/university has SMS you should be able to upgrade at no cost to you. Talk to your IT people.
The new tool also allows you to generate code for a *.csv file etc. It's pretty cool.
per isakson
per isakson 2012년 12월 4일
R2012a has "Import data ..." in the File menu. Is that tool more powerful in R2012b?
Sean de Wolski
Sean de Wolski 2012년 12월 5일
@Per, in 12b it can handle text files and weirder things that are not well defined.

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

Image Analyst
Image Analyst 2012년 12월 4일

0 개 추천

There seems to be no capability to skip rows in csvread() or dlmread() unless the skipped rows have the same format as the numerical table below the rows. So it appears that it can't handle skipping header lines with arbitrary strings on them. This would be a nice, and I think an easy to add, upgrade that many people have been wanting for a long long time. If you want, you could easily write your own to get certain lines, write them out to a temporary file, call csvread on that temporary file, then delete the temporary file. In the meantime you may have to read lines yourself with fgetl() and parse with textscan() or sscanf().

댓글 수: 3

Chandan
Chandan 2012년 12월 4일
The thing is since its many files, doing that would be hectic. I am trying to extract the entire column which goes from numbers 33.XXX, 57.XXX, 61.XXX, 61.XXX and so on.
Image Analyst
Image Analyst 2012년 12월 4일
It's not that hard, but if you want code that does it, just check the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/index?utf8=%E2%9C%93&term=csvread
Image Analyst
Image Analyst 2012년 12월 5일
Actually it looks like Sean's right. In R2012b it seems like importdata has the header-line-skipping capability that I was wanting for csvread and dlmread. I haven't tried it but that's just based on reading the help.

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

per isakson
per isakson 2012년 12월 4일
편집: per isakson 2012년 12월 4일

0 개 추천

  • your file has something like 18 headerlines
  • the data rows have a zillions fields, many of which are empty
  • the rows have both "text" and "numeric" fields
  • the file has a footer with text and a summary row
  • the files has many thousand rows
I would say that you must read the file in two steps
  • determine number of rows of header, data and footer
  • read the file with textscan.
The format string "must" be generated automatically, which can be done in the first step. Reading the file twice has a minor effect on the performance if it fits in the system cache.
I guess that few if any tools in the File Exchange handles footers

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

태그

질문:

2012년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by