Import multiple excel with different column size

4 Ansichten (letzte 30 Tage)
Nanda Dash
Nanda Dash am 23 Sep. 2021
Kommentiert: Nanda Dash am 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.

Antworten (1)

KSSV
KSSV am 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 Kommentar
Nanda Dash
Nanda Dash am 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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by