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!