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
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!