필터 지우기
필터 지우기

Summing numerical data of excel files in Matlab

조회 수: 1 (최근 30일)
Lucky
Lucky 2013년 10월 4일
댓글: Ali Hijazi 2022년 3월 1일
Hi to all matlab geniuses! I am new in matlab, hope somebody can help me. The question is following: I have 100 excel files with numerical data. I need to sum up relative columns of each file, thus creating a new excel file. Example: My 1st excel file content:
name1 10
name2 20
name3 30
name4 40
name5 50
Second excel file content:
name1 50
name2 40
name3 30
name4 20
name5 10
and other 98 are the same format..
So, I need final excel file like this:
name1 60
name2 60
name3 60
name4 60
name5 60
How to make it in Matlab??? Thank you very much in advance!!

채택된 답변

Cedric
Cedric 2013년 10월 4일
편집: Cedric 2013년 10월 4일
Assuming file names to be coded as follows: data_001.xlsx, data_002.xlsx, .., data_100.xlsx, you could build a solution based on the following approach
nFiles = 100 ;
for fId = 1 : nFiles
filename = sprintf( 'data_%03d.xlsx', fId ) ;
num = xlsread( filename ) ;
if fId == 1
buffer = num ; % See note 1.
else
buffer = buffer + num ; % See note 1.
end
end
Note 1: this assumes that there is only one column of numeric values in the file. If there are multiple, you have to select the relevant column, e.g. if it's column 3: buffer=num(:,3) and buffer=buffer+num(:,3).
This approach can be extended a little with code for e.g. taking all files from a specific folder, or matching names if they can be stored in various orders.
  댓글 수: 2
Lucky
Lucky 2013년 10월 4일
yeees, it works!! thank you very much!!
Cedric
Cedric 2013년 10월 4일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ronnel Jay
Ronnel Jay 2014년 7월 31일
help pls. how about if i have this kind of file in which contains random arrangements of names and i want to summarizing or addition of same name?
name1 50 name2 40 name3 30 name4 20 name5 10 name1 50 name2 40 name3 30 name4 20 name5 10 name1 50 name2 40 name3 30 name4 20 name5 10
  댓글 수: 2
Cedric
Cedric 2014년 8월 2일
If not already done, please post this as a new question.
Ali Hijazi
Ali Hijazi 2022년 3월 1일
Hello,
did you solve this ?
I have multiple files with different names for example : TF_a1_E1z_R1z.dat and TF_a1_E1x_R1y.dat
TF_a3_E8z_R15z.dat etc etc... how can it be resolved ? since i want to sum the second column of these numeric data
Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by