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: pdweight.m
    path of file: ./repos/malini/Codes/FC_EC_calculation code/DynamicFC/jplv7/spatial/weights
    
    the code of the file until where you have to start completion: function g=pdweight(xcoord,ycoord,lower,upper,RowStdOpt);
% PURPOSE: uses x,y coordinates to produce distance-based spatial weight matrices
%          The user is asked to input x and y coordinates, as well as a lower and upper
%          bound cutoff for the neighborhood.
% ------------------------------------------------------
% USAGE: W = pdweight(xcoord,ycoord,lower,upper,rowstdopt)
% where:     xcoord = x-direction coordinate
%            ycoord = y-direction coordinate
%            lower  = lower bound distance cut-off

    
function g=pdweight(xcoord,ycoord,lower,upper,RowStdOpt);
% PURPOSE: uses x,y coordinates to produce distance-based spatial weight matrices
%          The user is asked to input x and y coordinates, as well as a lower and upper
%          bound cutoff for the neighborhood.
% ------------------------------------------------------
% USAGE: W = pdweight(xcoord,ycoord,lower,upper,rowstdopt)
% where:     xcoord = x-direction coordinate
%            ycoord = y-direction coordinate
%            lower  = lower bound distance cut-off
%            uppper = upper bound distance cut-off
%            rowstdopt = 1 for row-standardization
%                      = 0 for no standardization
% ------------------------------------------------------
% RETURNS: 
%          W = a sparse weight matrix based on distance cut-offs
%              set by lower and upper input options
% ------------------------------------------------------

% written by: Shawn Bucholtz
% SBUCHOLTZ@ers.usda.gov
% USDA-ERS-ISD-ADB

%This function builds a sparse spatial weight matrix.
%The user is asked to input x and y coordinates, as well as a lower and upper
%bound cutoff for neighborhood.
%The user is given the option of indicating if they would like
%to Row-standarize the weight matrix (1=Row Standardized, 0=Not Row-Standardized)


%Declare inital values;
i=1;
p2=[1 1 -8888];
%Begin loop for each observation;

for i=1:(length(xcoord));
      j=1;
      p1=[1 1 -9999];%Make an inital value;
        %Begin loop to compute distance from observation i to all other observations;
      
            for j=1:(length(xcoord));

                if xcoord(i)==xcoord(j) & ycoord(i)==ycoord(j);
                    D=1;%This ensures that two places with the same x,y location will
                        %be defaulted to 1 distance unit away from eachother.
                        %This can happen in the case of two condos who are assocaited with one building location.
                else;
                    Xdist=abs(xcoord(i)-xcoord(j));
                    Ydist=abs(ycoord(i)-ycoord(j));
                    D = sqrt(Xdist^2 + Ydist^2);
                end