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: partial_legendre.m
    path of file: ./repos/d2d/arFramework3/ThirdParty/StrucID/adimat/runtime
    
    the code of the file until where you have to start completion: function [g_p, p] = partial_legendre(n,x,normalize)
%PARTIAL_LEGENDRE  Compressed local partial derivative of legendre.
%
%   [G_P,P] = PARTIAL_LEGENDRE(N,X,NORMALIZE) evaluates the local partial
%   derivatives of the function
%         P = legendre(N,X,NORMALIZE)
%   with respect to X. Here, N is the degree of the associated Legendre
%   functions and X is the point at which which legendre() and its
%   derivatives
    
function with
    % m = n. So, the following loop ends with m = n-1.
    for m = 0:n-1
        % For n = 1, the degree of z is 0. Since the dimension of the
        % return value of the function legendre() for a function with
        % degree 0 is different from nonzero degrees, this case needs a
        % special treatment. The above statement to generate the variable z
        %      z = legendre(n-1,x,normalize)
        % omits the first dimension of the return value for n=1.
        if n == 1
            py_px(m+1,:) = py_px(m+1,:) + scale(m+1)*(n+m).*z(:).';
        else
            py_px(m+1,:) = py_px(m+1,:) + scale(m+1)*(n+m).*z(m+1,:);
        end