metesub

PURPOSE ^

METESUB introduces a submatrix S of size m*n around the point [i j]

SYNOPSIS ^

function A=metesub(A,pto,S)

DESCRIPTION ^

 METESUB introduces a submatrix S of size m*n around the point [i j]
 of the matrix A.

 USE: B = metesub(A,[i j],subbloque);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % METESUB introduces a submatrix S of size m*n around the point [i j]
0002 % of the matrix A.
0003 %
0004 % USE: B = metesub(A,[i j],subbloque);
0005 
0006 function A=metesub(A,pto,S)
0007 
0008 a=size(A);
0009 i=pto(1);
0010 j=pto(2);
0011 s=size(S);
0012 m=s(1);
0013 n=s(2);
0014 pto=floor(pto);
0015 i=floor(i);
0016 j=floor(j);
0017 if floor(m/2)<m/2
0018    mf=i-ceil(m/2)+1;
0019    Mf=i+ceil(m/2)-1;
0020 else
0021    mf=i-floor(m/2)+1;
0022    Mf=i+floor(m/2);
0023 end
0024 if floor(n/2)<n/2
0025    mc=j-ceil(n/2)+1;
0026    Mc=j+ceil(n/2)-1;
0027 else
0028    mc=j-floor(n/2)+1;
0029    Mc=j+floor(n/2);
0030 end
0031 if (mf<1)|(Mf>a(1))|(mc<1)|(Mc>a(2))
0032    if (mf>a(1))|(Mf<1)|(mc>a(2))|(Mc<1)
0033           A=A;
0034    elseif ((mf<1)&(mc<1))&((Mf>=1)&(Mc>=1))
0035           fi=1-mf+1;
0036           ci=1-mc+1;
0037           A(1:m-fi+1,1:n-ci+1)=S(fi:m,ci:n);
0038    elseif ((mf<1)&(Mc>=a(2)))&((Mf>=1)&(mc<=a(2)))
0039           fi=1-mf+1;
0040           cf=n-(Mc-a(2));
0041           A(1:m-fi+1,a(2)-cf+1:a(2))=S(fi:m,1:cf);
0042    elseif ((Mf>a(1))&(mc<1))&((mf<=a(1))&(Mc>=1))
0043           ci=1-mc+1;
0044           ff=m-(Mf-a(1));
0045           A(a(1)-ff+1:a(1),1:n-ci+1)=S(1:ff,ci:n);
0046    elseif ((Mf>a(1))&(Mc>a(2)))&((mf<=a(1))&(mc<=a(2)))
0047           cf=n-(Mc-a(2));
0048           ff=m-(Mf-a(1));
0049           A(a(1)-ff+1:a(1),a(2)-cf+1:a(2))=S(1:ff,1:cf);
0050    elseif (mf<1)&((Mf>=1)&(mc>=1)&(Mc<=a(2)))
0051           fi=1-mf+1;
0052           A(1:m-fi+1,mc:Mc)=S(fi:m,1:n);
0053    elseif (mc<1)&((Mc>=1)&(mf>=1)&(Mf<=a(1)))
0054           ci=1-mc+1;
0055           A(mf:Mf,1:n-ci+1)=S(1:m,ci:n);
0056    elseif (Mf>a(1))&((mf<=a(1))&(mc>=1)&(Mc<=a(2)))
0057           ff=m-(Mf-a(1));
0058           A(a(1)-ff+1:a(1),mc:Mc)=S(1:ff,1:n);
0059    elseif (Mc>a(2))&((mc<=a(2))&(mf>=1)&(Mf<=a(1)))
0060          cf=n-(Mc-a(2));
0061          A(mf:Mf,a(2)-cf+1:a(2))=S(1:m,1:cf);
0062    end
0063 else
0064    A(mf:Mf,mc:Mc)=S;
0065 end

Generated on Fri 07-Mar-2014 13:29:20 by m2html © 2005