average of one column of many text file

조회 수: 2 (최근 30일)
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya 2016년 5월 20일
댓글: Arashdeep Singh 2021년 7월 10일
I have three hundrad text files and each have 4 columns.I have to do average of 3rd column of all the text files.It will come as a single column.How can we do this.

채택된 답변

KSSV
KSSV 2016년 5월 20일
txtfiles = dir '*.txt' ; % pick txt files in directory
Nfiles = length(txtfiles) ; % total number of files
iwant = zeros(Nfiles,1) ; % initialize the avg array
for i = 1:Nfiles % loop for each file
data = importdata(txtfiles(i).name) ; % load the data
iwant(i) = mean(data(:,3)) ; % get the mean
end
  댓글 수: 4
rebecca wise
rebecca wise 2020년 2월 3일
can this code work for xlsx files?
Arashdeep Singh
Arashdeep Singh 2021년 7월 10일
No, it cannot; it is specifically matlab code

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by