how to import multiple file and calculate a mean?

5 visualizaciones (últimos 30 días)
Ernest Adisi
Ernest Adisi el 31 de Ag. de 2018
Editada: Stephen23 el 31 de Ag. de 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)

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 31 de Ag. de 2018
Editada: KALYAN ACHARJYA el 31 de Ag. de 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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by