Extract data from multiple excel files

조회 수: 15 (최근 30일)
Mariana
Mariana 2020년 1월 10일
댓글: Nusrat Chowhdury 2022년 3월 30일
I am trying to extract data from a specific column from multiple excel files and save this columns in one table
D = 'C:\Users\Desktop\Analyze\';
for k=1:250
file = sprintf('Data_%d.xlsx',k);
filename = strcat('C:\Users\TR8E1MQ\Desktop\Analyze\',file);
x = xlsread(filename);
T = x(:,7);
end
This how I am extracting one column. I want to keep those and keep adding more values from other excel files.

채택된 답변

Guillaume
Guillaume 2020년 1월 10일
I would recommend you use fullfile instead of strcat to build paths. This way you don't have to worry about path separators.
Assuming that all files have the number of rows, this is how I'd do it:
source_folder = 'C:\Users\Desktop\Analyze'; %much more meaningful name than D
numfiles = 250;
data = []; %will be preallocated upon reading the first file, once we know the size of a column
for fileidx = 1:numfiles
filedata = readmatrix(fullfile(source_folder, sprintf('Data_%d.xlsx', fileidx)));
if fileidx == 1
data = zeros(size(filedata, 1), numfiles); %preallocate to the height of columns x num files
end
data(:, fileidx) = filedata(:, 7); %copy column 7 into output matrix
end
end
  댓글 수: 10
Mariana
Mariana 2020년 1월 11일
Thanks. You were right. Now, I have different cells and on each of them all of my values of that specific column are saved.
I would like to analyze these cells.
-Plot in a graph all of these values and find max. , min. and average values
How can I do this?
Nusrat Chowhdury
Nusrat Chowhdury 2022년 3월 30일
What is the code if I wanna take multiple columns of each excel file in the same way?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by