Import multiple excel with different column size

4 次查看(过去 30 天)
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.

回答(1 个)

KSSV
KSSV 2021-9-23
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 个评论
Nanda Dash
Nanda Dash 2021-9-29
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by