Element by Element Average of 100 .txt file Matrixes

1 vue (au cours des 30 derniers jours)
rwn
rwn le 21 Avr 2020
Commenté : rwn le 21 Avr 2020
I am working with 100 .txt files such as the one attached. Each file contains a matrix containing columns of X,Y,U,V. I would like to average these files element by element to construct and average matrix that can then be reshaped and plotted as seen in the code below.
Right now I am just using the large matrix from the first file which is attached below. I am trying to replace this initial matrix with the average matrix of all 100 .txt files.
All .txt files are labeled B00001, B00002, and so on. Is there anyway to read and compile all of the matrixes into a single average one?
type B00001.txt;
A=dlmread('B00001.txt', '',1,0);
X = reshape(A(:,1),124,173);
Y = reshape(A(:,2),124,173);
U = reshape(A(:,3),124,173);
V = reshape(A(:,4),124,173);
pcolor(X,Y,U);
hold on
shading interp
colormap(jet);
colorbar

Réponse acceptée

David Hill
David Hill le 21 Avr 2020
A=dlmread('B00001', '',1,0);
for k=2:100;
A=A+dlmread(['B00',sprintf('%03d',k)], '',1,0);
end
A=A/100;
  1 commentaire
rwn
rwn le 21 Avr 2020
Thank you, this is very helpful!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by