Appending tables from excel with different column order
2 views (last 30 days)
Show older comments
Hi,
I am using teh following codes to append a large number of excel data
List = dir(fullfile(Base,'*.xls'));
Result = cell(1,numel(List));
for k = 1:numel(List)
File = fullfile(Base,List(k).name);
if k==1
opts = detectImportOptions(File);
A = readtable(File,opts); %
t20142018=A;
else
A = readtable(File,opts);
t20142018=[t20142018;A];
end
end
However, I discovered that some files don't have the same order which resulted data of different columns to be merged in a single column . So my question is ow to make sure that columns with the same names from different excel files are appended together with the same format. In other words, if an excel file has the following header:
Rank Date Name Hostile
and another excel file has the following order
Rank Name Date Hostile
How can I append these files correctly in an aggregate table (t2014t2018 in my codes)
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!