1 |
function [out] = cshift(in,DIM,shift) |
2 |
%function [out] = cshift(in,DIM,shift) |
3 |
% |
4 |
% Replicate the CSHIFT function in F90 (?). |
5 |
% |
6 |
% G. Gebbie, MIT-WHOI, Dec 2003. |
7 |
|
8 |
totaldims = ndims(in); |
9 |
index = 1: totaldims; |
10 |
index(index==DIM) = []; |
11 |
index = [DIM index]; |
12 |
sizin = size(in); |
13 |
in = permute(in,index); |
14 |
in = reshape(in,sizin(DIM),prod(sizin)./sizin(DIM)); |
15 |
|
16 |
if shift>=0 |
17 |
shift = shift - size(in,1); |
18 |
end |
19 |
|
20 |
out = [in(shift+1+size(in,1):size(in,1),:);in(1:size(in,1)+shift,:)]; |
21 |
out = reshape(out,sizin(index)); |
22 |
out = ipermute(out,index); |