I have 200 files with 20 columns each. The 1st column remains the same for all files. I want to sum up all 2nd columns from 200 files, .....20th columns from 200 files. I want the first column to remain the same.

Answers (1)

Hi you have to use a for-loop to access your data and then add up the colums.
First use dir to get your files
files = dir('C:\users\...');
then create your output
Output = [];
then loop through your data, import them (that of course depends on the type of data):
Be sure to use double as datatype or it wont run.
for iFile = 1:size(files,1)
tempFile = importdata(fullfile(files(iFile).folder, files(iFile).name)); % get data
if iFile = 1
Output = tempFile; % write data for first run through the loop
else
tempFile(:,1) = 0; % make first column zeros so it doesnt change on adding up
Output = Output + tempFile; % add up data
end
end

Asked:

on 15 Feb 2019

Answered:

on 15 Feb 2019

Community Treasure Hunt

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

Start Hunting!