Loop through excel files and save output to 1 file
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
krysten spencer
am 5 Mär. 2018
Beantwortet: umichguy84
am 5 Mär. 2018
I would like this code to run through multiple files(which it does already) but then save the output in a new excel file - each row being a new file.
ext='.xlsx';
xl_file_list=dir(['p_*' ext]);
xl_file_list={xl_file_list(:).name};
xl_response_list=cellfun(@(x) ['p' x(3:(end-length(ext))) 'r' ext],...
xl_file_list,'uniformoutput',false);
for file_number=1:length(xl_file_list)
outputfilename=xl_response_list{file_number};
numData = xlsread(xl_file_list{file_number});
p = outputfilename
TP1 = numData(:,1)
TP2 = numData(:,2)
TP3 = numData(:,3)
TP4 = numData(:,4)
tp1 = sum(TP1)
tp2 = sum(TP2)
tp3 = sum(TP3)
tp4 = sum(TP4)
data = {p,tp1,tp2,tp3,tp4}
end
0 Kommentare
Akzeptierte Antwort
umichguy84
am 5 Mär. 2018
You want to add to the data every loop and write it out once at the end. Before loop data = repmat(cell(1,4),length(xl_file_list),1); % Preallocate for speed
Each loop data(file_number) ={p,tp1,tp2,tp3,tp4};
After loop xlswrite(OutFilename, data)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Downloads finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!