how to import multiple file and calculate a mean?

1 Ansicht (letzte 30 Tage)
Ernest Adisi
Ernest Adisi am 31 Aug. 2018
Bearbeitet: Stephen23 am 31 Aug. 2018
I have this code which works fine. it take one file and reshapes into matrices to plot a contour. i now want multiple files to import then calculate and plot a mean of the amount of files. can you show using a simple for loop please.
it takes the data from the 4 columns in the uploaded file and reshapes them into 4 matrices.
B = load ('B02490.txt');
c = 214;
r = length(B)/c;
U = zeros(r,c);
V = U;
for j=1:r
idx1 = (j-1)*c +1;
idx2 = j*c;
U(j,:) = B(idx1:idx2,3);
V(j,:) = B(idx1:idx2,4);
y(j) = B(idx1,2);
end
Nx = r;
Ny = c;
uu = zeros(Ny,Nx);
vv = uu;
tmp = zeros(r,1);
for i=1:Nx
vv(:,i) = U(i,:);
end
jj=1;
for i=1:c
for j=1:r
idx = r+1-j;
tmp(j) = -V(idx,i);
end
uu(jj,:) = tmp;
jj = jj+1;
end
pix_m=0.1215e-3;
for i=1:r
idx = c*(i-1)+1;
x(i) = B(idx,2);
end
y = B(1:c,1);
xm = x.*pix_m;
ym = y.*pix_m;
dt=0.0005;
uu = uu.*pix_m./dt;
vv = vv.*pix_m./dt;
[X,Y] = meshgrid(xm,ym);
figure
contourf(X,Y,vv,10)

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 31 Aug. 2018
Bearbeitet: KALYAN ACHARJYA am 31 Aug. 2018
%Save all files in symmetrically before doing the operation
%Names for example f1,f2,f3...
%Save the folder of filess in the current directory
path_directory='folder_name_here';
original_files=dir([path_directory '/*.txt']);
for k=1:length(original_files)
filename=[path_directory '/' original_files(k).name];
file_t=load('filename.txt');
% Next do your operation and finding
%After read one file >>Main Code here
%After that Next iteration for next file
end
%For mean calculation read here

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by