Reputation: 1485
I have one code to shift left and shift right with 2D data in Matlab. There are codes
function shift = shiftL(M)
shift = [ M(:,2:size(M,2)) M(:,size(M,2)) ];
function shift = shiftR(M)
shift = [ M(:,1) M(:,1:size(M,2)-1) ];
I want to apply above codes to 3D data input. How to modify above codes for 3D data? Thank you
function shift = shiftL3D(M)
function shift = shiftR3D(M)
Upvotes: 0
Views: 242
Reputation: 2898
function shift = shiftL3D(M)
shift = cat (3, M(:,:,2:size(M,3)) , M(:,:,1) );
function shift = shiftR3D(M)
shift = cat (3,M(:,:,end), M(:,:,1:size(M,3)-1) )
Upvotes: 1
Reputation: 1141
function shift = shiftL3D(M)
shift = cat(size(M,3),M(:,:,2:size(M,3)), M(:,:,1));
function shift = shiftR3D(M)
shift = cat(size(M,3),M(:,:,end),M(:,:1:size(M,3)-1));
Upvotes: 0