- https://in.mathworks.com/help/releases/R2023a/matlab/ref/corrcoef.html
Two-point statistics from 3D variables
9 views (last 30 days)
Show older comments
Hi guys, I have a two 3D variables for a each time step. I want to construct the two point statistics but I guess I'm doing something wrong.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1017845/image.png)
I know that the theoretical formulation of a two-point cross correlation is the one written above.
Let's for sake of simplicity ignore the normalization, so I'm focusing on the numerator, that is the part I'm struggling with.
So, my two variables are two 3D matrix, with the following notation phi(x,y,z) = phi(i,j,k), same for psi.
My aim is to compute a 3d correlation, so given a certain reference point Reference_Point = (xr,yr,zr), I proceeded as follows (see the first alternative below), but since in the Channel flow (the data I'm using are 3D velocity fields from DNS simulation) the x and z direction are homogenous I tried also the second alternative. But I guess I'm doing something really wrong.
ps: of course, that value of R is calculated for every time step and then I make a mean out of all the values obtained at each time step.
Thank you in advance for reply
for ix = 1:Nx
for iy = 1:Ny
for iz = 1:Nz
R = phi(xr,yr,zr).*psi(ix,iy,iz);
end
end
end
%% Second alternative
for ix = 1:Nx
for iy = 1:Ny
for iz = 1:Nz
R = phi(ix,yr,iz).*psi(ix,iy,iz);
end
end
end
0 Comments
Answers (1)
Abhimenyu
on 25 Sep 2023
Hi Marco Aratiano,
I understand that you want to use correlation on two matrices at a reference point on different steps. I would suggest you use column vector approach on matrices as follows:
% Loop through each time step
for t = 1:numTimeSteps
% Extract the values at the reference point for the current time step
phi_ref = phi(xr, yr, zr, t);
psi_ref = psi(xr, yr, zr, t);
% Compute the cross-correlation between phi and psi at the reference point
correlation = corrcoef(phi_ref(:), psi_ref(:));
R = correlation(1, 2);
% Extract the cross-correlation coefficient
% Store the cross-correlation coefficient for the current time step
R_values(t) = R;
end
You can take the mean of ‘R_values’ to finally find the correlation. For more information on corrcoef, go through the below link:
Thank you,
Abhimenyu
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!