我有一个代码向左移动并在Matlab中使用2D数据向右移动。有代码
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) ];
我想将以上代码应用于3D数据输入。如何修改上述3D数据代码?谢谢
function shift = shiftL3D(M)
function shift = shiftR3D(M)
答案 0 :(得分:1)
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) )
答案 1 :(得分:0)
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));