how to create a mean velocity matrix from multiple .dat files and plot the mean profile?

3 visualizaciones (últimos 30 días)
I have a folder of x no of *.dat files. So far I've imported 1 file and reshaped the columns to get matrices for each column. e.g for 1 dat file:
filename='B00049.dat';
delimiterIn= ' ';
headerlinesIn = 3;
A= importdata(filename,delimiterIn,headerlinesIn);
%% Matrices%%%%
c = 214;%columns i
r = 134;%rows j
dt= 0.0005;
x=reshape(A.data(:,1),r,c);
y=reshape(A.data(:,2),r,c);
u=reshape(A.data(:,3),r,c);
v=reshape(A.data(:,4),r,c);
I now want to import multiple files and creat a mean velocity matrix fro u and v then plot a profile. How can this be done ? Thanks
  2 comentarios
Ernest Adisi
Ernest Adisi el 31 de Jul. de 2018
thanks for the response, i'm trying to create a path to the folder containing all the files then perform a loop in order to make the 4 matrices for each file, then finally create a mean velocity matrix from the average of the last two columns in the 2 dat files. Hope that makes sense

Iniciar sesión para comentar.

Respuesta aceptada

jonas
jonas el 31 de Jul. de 2018
Editada: jonas el 31 de Jul. de 2018
files=dir('*.dat') %If files are in current dir, otherwise enter entire path
%%Preallocate some cells
x=cell(1,numel(files))
y=cell(1,numel(files))
u=cell(1,numel(files))
v=cell(1,numel(files))
%%Loop over all files
for i=1:numel(files)
filename=files(i).name
delimiterIn= ' ';
headerlinesIn = 3;
A= importdata(filename,delimiterIn,headerlinesIn);
c = 214;%columns i
r = 134;%rows j
dt= 0.0005;
%%Save results
x{i}=reshape(A.data(:,1),r,c);
y{i}=reshape(A.data(:,2),r,c);
u{i}=reshape(A.data(:,3),r,c);
v{i}=reshape(A.data(:,4),r,c);
end
When you have all the data stored in cells, you can concatenate along the third dimensinon and take the average. I assume all files share the same size?
V = cat(3, v{:});
mean(V,3)
  25 comentarios
Ernest Adisi
Ernest Adisi el 9 de Ag. de 2018
you're right. It worked. Thank you so much again for all the help. Appreciate it

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance 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