I have a KxLxM matrix A which is an image with a feature vector, length M, for each pixel location. I have also have a feature vector v, length M. At each pixel location of image A i want to calculate the correlation of the pixel's feature vector with my feature vector v.
I've already done this using a loop, but loops are slow in matlab. Does anyone have a suggestion of how to vectorize this?
function test()
A = rand(4,5,3);
v = [1 2 3];
c = somecorr(A, v);
size(c)
function c = somecorr(a,v)
c = a(:,:,1).*0;
for y = 1:size(a,1)
for x = 1:size(a,2)
c(y,x) = corr2(squeeze(a(y,x,1:length(v)))',v);
end
end
>>test()
ans =
4 5