how to import multiple file and calculate a mean?
2 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
回答(1 个)
KALYAN ACHARJYA
2018-8-31
编辑:KALYAN ACHARJYA
2018-8-31
%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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!