Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Summing data from different excel files

조회 수: 1 (최근 30일)
Vlatko Milic
Vlatko Milic 2018년 1월 15일
마감: MATLAB Answer Bot 2021년 8월 20일
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! :)

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by