Hi MATLABbers!
I should have posted here ages ago, but apparently I enjoy getting tangled in knots. Many thanks in advance, and apologies for such a long post, but I wanted to really clarify what my problem is!
Here's what I'm trying to do:
1. I have a vector field of velocities corresponding to the flow patterns in a population of kidney cells. The field is split into V_x and V_y in two different matrices. These matrices are often 100 x 100.
2. I would like to compute the *spatial* correlation length (correlation coefficient as a function of distance) within a single instance of the vector field. Here is why: I am trying to demonstrate that I can control how these cells behave, and I already can cleanly show this with order parameters and pretty plots, but correlation length is a standard benchmark in the swarm community. So, I would like to be able to say that I have motion/orientations that are coordinated across a distance of L. This is very similar to an Nth nearest neighbor correlation. The best image I could find for the general equation is here:
http://patentimages.storage.googleapis.com/WO2011047033A2/imgf000021_0001.png
3. Here is my understanding of how to do this conceptually: Go to an element and then multiply that vector by every other element in the matrix *that is ~a certain distance 'R' away*. Repeat this operation for every element in the system, average the correlations, normalize, and then iterate the radius so that we are now multiplying a given element by those elements that are ~'R+dR'. In other words, I am correlating a given element against those elements at an increasing radius away from it, and I am doing this over the whole system. The normalization is similar to what is shown in the link above.
4. Here is how I have tried to do it:
I have tried many methods like element-by-element looping (seems to work but a nightmare) and k-Nearest-Neighbors (seems to work, but also seems like it won't scale well beyond a few elements/radii and I can't seem to parse the output vector of cells into something I can use for multiple search points at one time).
What I'd prefer to use for speed and 'simplicity' is a cross-correlation method that works only with the data matrices, but I'm clearly missing some things
To this end,
%I load a bunch of data in here and process it
% u is a 100 x 100 matrix of x-velocity components
% ur = u-mean2(u); %=residuals of u
for(NN=1:1:maxN)
wind=double(bwmorph(imcircle(2*NN+1),'remove')); %Create window matrix
% wind is 2*NN+1 and contains all zeroes except at a radius of 2*NN+1
%Ex: for the 1st nearest neighbor, wind =...
% 1 1 1
% 1 0 1
% 1 1 1
localprod=conv2(ur,wind,'same'); %not sure about 'same' here, but it is for the next line
corrprod = ur.*localprod; %element-wise mult by cross-corr outputs
upstairs = mean2(corrprod); %I think that's the definition of the operation I want
downstairs = mean2(u.*u); %similar to what I should normalize by, but not correct
%downstairs = numel(find(wind)); %alternate normalization...sort of
C(NN) = upstairs/downstairs; %output CorrCoeff(distance)
end
%Thanks!
%D