circular shifting a vector/matrix - Problem



Hello,

I have a problem with circular shifting a vector/matrix that is keeping
my mind absolutely crazy.

I know and use the "circshift" function (many thanks to the one that
designed this function, as it helps me to solve almost all of my
problems ;-).

I have two matrices, each one with equal dimensions M-by-N, and I am
using "corr2" to calculate the two-dimensional correlation coefficient
between them. The second matrix is "almost similar" to the first one,
but its columns are rotated in relation to the columns of the first
one.

So, I am using "corr2" as a way to compute the similarity between these
two matrices. As one is shifted to the other, I compute "corr2" between
them, rotate by one column one of the matrices, compute "corr2" between
them, then rotate again, compute "corr2", and so on...

Each time I rotate one of the matrices, I keep the correlation
coefficient. At the end, when all columns are shifted I end up with a
vector of correlation coefficients. Then I compute
max(vector_coef_corr) to see where the two matrices are most similar to
each other.

My problem is that, as my matrices have a large number of columns, the
circular shifting is a time consuming procedure (of course I know that
"corr2" is also a time consuming procedure, but I _have_ to use this
function - as it is part of the idea of my algorithm). How can I speed
the circular shifting process? I am using a for loop (argh!!!!!)
nowadays, because I couldn't thing in any other solution (-:. Is there
a way to vectorize this thing?

Here you have a piece of my code:

corrCoef = zeros(1, numColMatrix01);
for shiftSize = 1:numColMatrix01,
corrCoef(shiftSize) = corr2(Matrix01, Matrix02);
Matrix01 = circshift(Matrix01, [0 shiftSize]);
end;
corrCoef = max(corrCoef);

Many thanks in advance,
JKvdPoel

.


Quantcast