associated Legendre functions could be found from Legendre functions according to the following formula

so in MATLAB you can define a function like this
function plm = assocLegendre(l,m)
    % get symbolic associated legendre function P_lm(x) based on
    % legendre function P_l(x)
    syms x;
    % get symbolic form of Legendre function P_l(x)
    leg = legendreP(l,x);
    % differentiate it m times
    legDiff = diff(leg,x,m);
    % calculate associated legendre function P_lm(x)
    plm = ((-1)^m)*((1 - x^2)^(m/2))*legDiff;
end
to get associated Legendre functions in symbolic form.


