How to read many csv files at once and then extract certain column from it?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have about 115 csv files with 9 columns and rows ranging from 10^6 to 10^7. I want to read all of them at once and extract the necessary columns from it later. I tried the following code below for combining them. But I am not being able to extract a certain column. Any suggestion?
clear
clc
file=dir('*.csv');
num=length(file);
combined=cell(length(file),1);
for i=1:num
combined{i}=xlsread(file(i).name);
end
댓글 수: 0
채택된 답변
Walter Roberson
2021년 12월 24일
file=dir('*.csv');
num=length(file);
combined = cell(num, 1);
for i=1:num
combined{i}=xlsread(file(i).name);
end
desired_column = 7;
certain_column_cell = cellfun(@(C) C(:,desired_column), combined, 'uniform', 0);
If all of the files have the same number of rows and you want to combine into one matrix,
certain_column_matrix = horzcat(certain_column_cell{:});
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!