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.

1 回表示 (過去 30 日間)
file 1:
1 2 3 4
2 2 3 2
file 2:
1 3 4 1
2 1 3 2
output should be:
1 5 7 5
2 3 6 4

回答 (1 件)

StefBu
StefBu 2019 年 2 月 15 日
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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by