Sum up data from various excel files in different folders

1 Ansicht (letzte 30 Tage)
Vlatko Milic
Vlatko Milic am 4 Jan. 2018
Kommentiert: Vlatko Milic am 4 Jan. 2018
Hi, I am quite new to Matlab and have a question for you experts :) I want to sum up specific rows in a certain column in different excel-files located in various folders. The search path is attached (see matlab.jpg) where Matlab_Esignatur is the home location, "eltest" contains different addresses (such as Berzeliigatan 14) that are folders, and within each adress there are a number of excel-files. The no. of excel-files differs from each adress/folders. The excel-files are also attached. I only want to sum up the value of certain rows in column G with the column value of 1, and not 2, in column A (see matlab2.jpg).
What I have managed so far is to read the different street names or folders, see matlab3.jpg, where the code is also seen. What is my next step?
Thank you!
  2 Kommentare
Jan
Jan am 4 Jan. 2018
The screenshots are very inconvenient to read. Please post the information as text instead. The image containing the "search path" is not useful, because '"eltest" contains different addresses (such as Berzeliigatan 14)' is not clear.
Vlatko Milic
Vlatko Milic am 4 Jan. 2018
Hi, thank you. Here comes a revised version :) I want to sum up specific rows in a certain column in different excel-files which are located in various folders. The search path is as follows: Matlab_Esginatur (original folder)=>Folders named as various adresses => Each folder/adress containing a different number of Excel files. What I want do to within each excel file is to sum up the value of certain rows in column G with the column value of 1, and not 2 (each position has the value of 1 or 2), in column A.
What I have managed so far is to read the different street names or folders. The code looks like follows:
path1 = 'Eltest'; subfolderInfo = dir(path1); subfolderNames = {subfolderInfo.name}; subfolderNames(ismember(subfolderNames,{'.','..'}))=[]; cd 'Eltest';
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) file_no
ImportedData{fol_no,file_no} = readtable(char(fullfile(fileInfo(1).folder,fileNames(file_no))));
%ImportedData{fol_no,file_no} = readtable(char(fullfile(fileInfo(fol_no).folder,fileNames(file_no)))) end end total = table(ImportedData,'RowNames',subfolderNames)
The output reads:
total =
10×1 table
ImportedData
____________
Berzeliigatan 12 [1x14 cell]
Berzeliigatan 14 [1x14 cell]
Berzeliigatan 16 [1x14 cell]
Berzeliigatan 18 [1x14 cell]
Gråbrödragatan 10 [1x14 cell]
Vasavägen 21 [1x14 cell]
Vasavägen 23A [1x14 cell]
Vasavägen 23B [1x14 cell]
Vasavägen 25A [1x14 cell]
Vasavägen 25B [1x14 cell]
What is my next step?
Thank you!

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by