MATLAB: What is the fastest, circshift or indices

circshift efficiency parallel matrices

Hi
I'm trying to improve the efficiency of my algorithm. I need to compute something like :
Y(2:end-1,:) = X(2:end-1,:) + X(1:end-2,:) – X(3:end,:)
For Y and X n by m matrices. I was wondering if it was faster to do it as it is above, or using circshift :
Y = X + circshift(X,[-1,0]) – circshift(X,[+1,0]).
I've done a few tests but I can't get a clear idea… The aim is to do this on pretty big matrices on a cluser with multiple cores…
Any idea ? Thanks.
Stéphane

Best Answer

Just use conv2
Y=conv2(X,[-1;1;1],'valid');
As for circshift, it is not a builtin function and, if you look inside it
>>type circshift
you will see that it does pretty much the same indexing as you are doing. So, I wouldn't expect it to be a competitive approach.