Combine multiple tables into one table and export as an excel file
25 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I need to generate an excel file from multiple tables in my workspace, catch is all the tables have different number of rows, so I want to align them as best as possible using the first column of each table and push them out to an excel file.
I also need to put out a separate excel file for each table, is there a way to loop through the tables and generate an excel file for each of them…. So basically, how can I change the file name (meaning the excel file that i want to generate) every iteration to the appropriate table name which is at very last part of the directory/path
If it’s any help, I’ve attached a few tables and a piece of my code for a reference.
0 Commenti
Risposta accettata
KSSV
il 3 Nov 2021
files = dir('*.mat') ; % you are in the folder where mat files are present
N = length(files) ;
T = cell(N,1) ;
for i = 1:N
thisfile = files(i).name ;
temp = struct2cell(load(thisfile));
T{i} = temp{1} ;
% Write each tble to excel file
[thepath,name,extn] = fileparts(thisfile) ;
outfile = [files(i).folder,filesep,name,'.xlsx'] ;
writetable(T{i},outfile);
end
2 Commenti
Stephen23
il 3 Nov 2021
temp = struct2cell(load(thisfile));
T{i} = temp{1} ;
can be simplfied to
T(i) = struct2cell(load(thisfile));
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!