average of one column of many text file

2 vues (au cours des 30 derniers jours)
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya le 20 Mai 2016
Commenté : Arashdeep Singh le 10 Juil 2021
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.
  1 commentaire
Azzi Abdelmalek
Azzi Abdelmalek le 20 Mai 2016
Your question is not clear

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 20 Mai 2016
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 commentaires
rebecca wise
rebecca wise le 3 Fév 2020
can this code work for xlsx files?
Arashdeep Singh
Arashdeep Singh le 10 Juil 2021
No, it cannot; it is specifically matlab code

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by