フィルターのクリア

How to read many csv files at once and then extract certain column from it?

1 回表示 (過去 30 日間)
Anirban Mandal
Anirban Mandal 2021 年 12 月 24 日
編集済み: Anirban Mandal 2021 年 12 月 24 日
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

採用された回答

Walter Roberson
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{:});
  1 件のコメント
Anirban Mandal
Anirban Mandal 2021 年 12 月 24 日
編集済み: Anirban Mandal 2021 年 12 月 24 日
I tried cell2mat now to convert the cell into an array. It works fine also.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by