필터 지우기
필터 지우기

reading an combining excel files

조회 수: 1 (최근 30일)
Lotte Piek
Lotte Piek 2023년 2월 6일
댓글: Lotte Piek 2023년 2월 6일
Hi everyone,
I have a folder with excel files with I would all like to load in and combine. Is this a possibility? I want to prevent loading them in one-by-one and then combining them one-by-one since it contains around a 100 excel files with all just one row of heading and one row of data.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 6일
There are a few different ways to get this task done. One of them is this one if your data files have the same number of numerical data sets (there is just one row of data in each file you stated):
FILE = fullfile('C:\Users\...', '*.xlsx'); % Directory where the files are residing.
LIST = dir(FILE);
N = length(LIST); % N number of files
Ncols = ??? % Ncols how many columns of data in
D = zeros(N, Ncols);
for ii = 1 : N
FFName = fullfile(LIST(ii).folder, LIST(ii).name);
DATA = readmatrix(FFName);
D(ii, :) = DATA; % NOW D contains all data from 100 files
end
  댓글 수: 1
Lotte Piek
Lotte Piek 2023년 2월 6일
thank you very much! Would it be a possibility to keep the header ?

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

추가 답변 (1개)

Vineeta Shukla
Vineeta Shukla 2023년 2월 6일
편집: Vineeta Shukla 2023년 2월 6일
Hi,
From my understanding, you can use the function spreadsheetDatastore to manage and import the data when you have data stored across multiple spreadsheet files.
Here is an example from documentation:
https://www.mathworks.com/help/matlab/import_export/read-a-sequence-of-spreadsheet-files.html
Here is a link to the documentation to understand more about spreadsheetDatastore: https://www.mathworks.com/help/matlab/ref/matlab.io.datastore.spreadsheetdatastore.html

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by