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.
채택된 답변
추가 답변 (1개)
Walter Roberson
2015년 7월 28일
fmt = '%*f%f%*f%*f%*[\n]';
fid = fopen('filename.csv', 'rt');
datacell = textscan(fid, fmt, 'Delimiter', ',', 'HeaderLines', 1);
fclose(fid);
table_x = datacell{1};
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!