As the tittle suggests I am wondering if it is possible to circshift the columns of an array with a different shiftsize in each column without using a for loop.
I want to do this
without a loop. Is it possible?
No products are associated with this question.
[m,n] = size(a); b = rem(shiftindex-1,m)+1; c = rem(bsxfun(@plus,m + 1 - b - m*(b == 0),(0:m-1)')-1,m)+1; out = a(bsxfun(@plus,c,m*(0:n-1)));
Where is Anrei's answer??? It was here before 2 minutes ago.
Is an answer deleted after accepting a previous one?
I had some question on it that why?
He proposed this:
[m,n] = size(a); out = a(bsxfun(@plus,toeplitz(1:m,[1,m-(0:n-2)]),(0:n-1)*m));
Apart from the fact that its hardcore, my question would be what would be the case if the shiftindex was not linear..
shiftindex=[2 2 10 5];