Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Ernest Adisi
Ernest Adisi il 31 Lug 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

Accedi per commentare.

Risposta accettata

jonas
jonas il 31 Lug 2018
Modificato: jonas il 31 Lug 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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by