How to select one column of data from a csv file containing headers and strings?

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.

 채택된 답변

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)

추가 답변 (1개)

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

Thanks, but that only returns a 1x1 cell, specially 1008, which is B2. I want all the cells from B2 to BN, where N is the number of rows in the file.
Stephen23
Stephen23 2015년 7월 28일
편집: Stephen23 2015년 7월 28일
Can you please upload the datafile: edit your question, click on the paperclip icon, and then push both the Choose file and Attach file buttons.

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

카테고리

제품

질문:

2015년 7월 28일

댓글:

2015년 7월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by