function [b] = exch_llc(a,o) [nnx nny]=size(a); if (nnx/4~=round(nnx/4)) error('x-dimension needs to be divisible by 4') end n4 = nnx/4; % pull array appart ca = a(:,end-n4+1:end); lla = a(:,1:end-n4); % do the tricky bit first because we need the ll part for that [nx,ny]=size(ca); lln = lla(:,end-o+1:end); cb = NaN*ones(nx+2*o,ny+o); % interior cb(o+1:nx+o,1:ny)=ca; % cb(1:o,:) = flipud(lln(n4*3-o+1:n4*4,:))'; % right cb(end-o+1:end,:) = fliplr(lln(1:n4+o,:))'; % left % top cb(o+1:o+n4,end-o+1:end) = flipud(fliplr(lln(2*n4+1:3*n4,:))); cb(o+n4+1:o+2*n4,end-o+1:end) = fliplr(flipud(lln(n4*3+1:n4*4,:))); cb(o+n4*2+1:o+3*n4,end-o+1:end) = flipud(lln(1:n4,:)); cb(o+n4*3+1:o+4*n4,end-o+1:end) = flipud(lln(2*n4+1:3*n4,:)); % now exchange regular part: [nx,ny]=size(lla); llb=NaN*ones(nx+2*o,ny+o); llb(o+1:o+nx,o+1:o+ny)=lla; % Interior %b(o+1:o+nx,o+ny+(1:o))=a(:,ny:-1:ny-o+1); % N %b(o+1:o+nx,1:o)=a(:,o:-1:1); % S llb(o+nx+(1:o),:)=llb(o+1:o+o,:); % E llb(1:o,:)=llb(o+nx-o+1:o+nx,:); % W % put both parts together b = [llb cb];