You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: adaptivemedian.m
    path of file: ./repos/Detection-of-Breast-Cancer-using-Neural-Networks
    
    the code of the file until where you have to start completion: function Output=adaptivemedian(GrayScaleImage);

        NoisyImage=GrayScaleImage;
        NoisyImage=double(GrayScaleImage);
        [R C P]=size(NoisyImage);
        OutImage=zeros(R,C);
        Zmin=[];
        Zmax=[];
        Zmed=[];
        

        for i=1:R
        
            for j=1:C
                       if (i==1 & j==1)


                  % for right top corner[8,7,6]
                        elseif (i==1 & j==C)


                    % for bottom left corner[2,3,4]
                        elseif (i==R & j==1)


                             % for bottom right corner[8,1,2]

                        elseif (i==R & j==C)



    
function Output=adaptivemedian(GrayScaleImage);

        NoisyImage=GrayScaleImage;
        NoisyImage=double(GrayScaleImage);
        [R C P]=size(NoisyImage);
        OutImage=zeros(R,C);
        Zmin=[];
        Zmax=[];
        Zmed=[];
        

        for i=1:R
        
            for j=1:C
                       if (i==1 & j==1)


                  % for right top corner[8,7,6]
                        elseif (i==1 & j==C)


                    % for bottom left corner[2,3,4]
                        elseif (i==R & j==1)


                             % for bottom right corner[8,1,2]

                        elseif (i==R & j==C)


                            %for top edge[8,7,6,5,4]

                        elseif (i==1)


                                                    % for right edge[2,1,8,7,6]

                        elseif (i==R)

                                % // for bottom edge[8,1,2,3,4]

                        elseif (j==C)


                                 %// for left edge[2,3,4,5,6]

                        elseif (j==1)





                       else



                                     SR1 = NoisyImage((i-1),(j-1));
                                     SR2 = NoisyImage((i-1),(j));
                                     SR3 = NoisyImage((i-1),(j+1));
                                     SR4 = NoisyImage((i),(j-1));
                                     SR5 = NoisyImage(i,j);
                                     SR6 = NoisyImage((i),(j+1));
                                     SR7 = NoisyImage((i+1),(j-1));
                                     SR8 = NoisyImage((i+1),(j));
                                     SR9 = NoisyImage((i+1)),((j+1));
                                     TempPixel=[SR1,SR2,SR3,SR4,SR5,SR6,SR7,SR8,SR9];
                                     Zxy=NoisyImage(i,j);
                                     Zmin=min(TempPixel);
                                     Zmax=max(TempPixel);
                                     Zmed=median(TempPixel);
                                     A1 = Zmed - Zmin;
                                     A2 = Zmed - Zmax;

                                     if A1 > 0 && A2 < 0

                                          %   go to level B
                                          B1 = Zxy - Zmin;
                                          B2 = Zxy - Zmax;
                                          if B1 > 0 && B2 < 0
                                              PreProcessedImage(i,j)= Zxy;
                                          else
                                              PreProcessedImage(i,j)= Zmed;

                                          end