Import multiple excel with different column size

4 vues (au cours des 30 derniers jours)
Nanda Dash
Nanda Dash le 23 Sep 2021
Commenté : Nanda Dash le 29 Sep 2021
Hi,
I have 100s of excel files to import. In some excel I have 40 columns and in some excel I have 60 columns.
For each type of excels 40 cloumns are common and having same header names. But the 20 columns in some file comes in middle of 40 columns. Is there any easy way to import all these excels together?
Thanks in adavance for your support.

Réponses (1)

KSSV
KSSV le 23 Sep 2021
xlFiles = dir('*.xlsx') ; % you are in the folder of files
N = length(xlFiles) ; % Total number of files
iwant = cell(N,1) ;
for i = 1:N % loop for each file
T = readtable(xlFiles(i).name) ; % read data as table
iwant = table2array(T) ; % save data as array
end
iwant is a cell array. You can access them using iwant{1}, iwant{3}, etc. You can convert it into matrix using cell2mat.
  1 commentaire
Nanda Dash
Nanda Dash le 29 Sep 2021
Hi, Thanks for the quick answer. This is how I am importing now. This sheet is having 40 variables
but in some sheets I have 60 variables. those extra 20 variables comes before "AbsoluteTime" column.
%% Set up the Import Options and import the data
opts = spreadsheetImportOptions("NumVariables", 40);
% Specify sheet and range
opts.Sheet = "Cycle_1";
opts.DataRange = "A2:";
% Specify column names and types
opts.VariableNames = ["Temperature1", "Temperature2", "Temperature3", "Temperature4", "AbsoluteTime", "RelativeTime", "Minutes"];
% Import the data
iwant = readtable("C:\Data\Excel\Cycle_0.xlsx", opts, "UseExcel", false);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by