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

2 次查看(过去 30 天)
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 个评论
Ernest Adisi
Ernest Adisi 2018-7-31
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

请先登录,再进行评论。

采纳的回答

jonas
jonas 2018-7-31
编辑:jonas 2018-7-31
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by