Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Summing data from different excel files

1 visualizzazione (ultimi 30 giorni)
Vlatko Milic
Vlatko Milic il 15 Gen 2018
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Hi,
I have a problem where I want to sum numerical values from various excel files in a subfolder. I have imported the data to Matlab in table format. Let's sat I have 10 different excel files, with 20 rows and 2 columns, from where I want to sum the values from column 1 to a new file, e.g. excel or directly in the matlab. This is my code:
for fol_no=1:numel(subfolderNames) fileInfo = dir(subfolderNames{fol_no}); fileNames = {fileInfo.name}; fileNames(ismember(fileNames,{'.','..'}))=[]; fol_no for file_no = 1:numel(fileNames) fileNames
ImportedData{fol_no,file_no} = readtable(char(fullfile(fileInfo(1).folder,fileNames(file_no))));
el=table2array(ImportedData{fol_no,file_no}(:,[1 7]));
%tar ut månadsdata
ind1=el(:,1)==1;
el1=el(ind1,:)
%summerar inom varje excel-fil
eltot=sum(el1(:,2))
%extraherar data som jag är intresserad av, dvs månadsbasis för samtliga
%byggnader
ImportedData_2{fol_no,file_no} = el1
ImportedData_3{fol_no,file_no} = eltot end end total = table(ImportedData_2,'RowNames',subfolderNames)
total2 = table(ImportedData_3,'RowNames',subfolderNames)
Is it better for me to perform this with the loop? Or during the post process work.
Thanks! :)

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by