Also, I want to attach the csv file. Can someone guide through that as well
Data extraction from CSV file
4 views (last 30 days)
Show older comments
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 Comments
Answers (3)
Sean de Wolski
on 4 Dec 2012
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 Comments
per isakson
on 4 Dec 2012
R2012a has "Import data ..." in the File menu. Is that tool more powerful in R2012b?
Sean de Wolski
on 5 Dec 2012
@Per, in 12b it can handle text files and weirder things that are not well defined.
Image Analyst
on 4 Dec 2012
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 Comments
Image Analyst
on 4 Dec 2012
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
on 5 Dec 2012
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
on 4 Dec 2012
Edited: per isakson
on 4 Dec 2012
- 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
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!