How to select one column of data from a csv file containing headers and strings?
4 views (last 30 days)
Show older comments
The csv files in question each contain five columns, and an unknown number of rows:
Suppose a file has N rows. I want to select all the data from B2 to BN and save them into a table.
I tried this:
table_x = csvread('filename.csv', 1, 1, [1, 1, Inf, 1]);
That doesn't work. It wants me specify the number of rows, which I don't know. I guess can't use csvread because I don't know what N is and because the file contains non-numeric data.
0 Comments
Accepted Answer
Peter Perkins
on 28 Jul 2015
It's not clear what you mean by, "save them into a table". It sound like you mean, "save that one column to a numeric variable". In R2013b or later, use readtable:
t = readtable('filename.csv')
x = t.X_mg_ % readtable will have modified X(mg)
More Answers (1)
Walter Roberson
on 28 Jul 2015
fmt = '%*f%f%*f%*f%*[\n]';
fid = fopen('filename.csv', 'rt');
datacell = textscan(fid, fmt, 'Delimiter', ',', 'HeaderLines', 1);
fclose(fid);
table_x = datacell{1};
3 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!