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: AFMT3.m
    path of file: ./repos/CS_MoCo_LAB/reconstruction/matlab/CS_LAB_matlab/utils/utils_TRAFO/FourierMellin
    
    the code of the file until where you have to start completion: function [ Y, gR, gPhi, gTheta ] = AFMT3( X, sigma, mAFMT, nAFMT, pAFMT, extrapVal, interpMethod, algorithm )
%Computes discrete approximation to analytic fourier-mellin transformation.
%Parameters:
%           x                   ...matrix with input data
%           sigma               ...strictly positive number, ensuring
%                                  existence of transformation
%           mAFMT               ...size of mellin-transformation (check)
%
%           nAFMT               ...size of 
    
function xCart = convToCart( xLogPol, gridR, gridPhi, gridTheta, gridX, gridY, gridZ, interpMethod )        
        %Perform conversion to cartesian coordinates:
%         convGridX   = reshape(exp(gridR) .* cos(gridPhi) .* cos(gridTheta),[], 1);
%         convGridY   = reshape(exp(gridR) .* sin(gridPhi) .* cos(gridTheta),[], 1);
%         convGridZ   = reshape(exp(gridR) .* sin(gridTheta),[], 1);
%         F = TriScatteredInterp(convGridX, convGridY, convGridZ, reshape(xLogPol, [], 1), interpMethod);
%         xCart       = F(gridX, gridY, gridZ);
        
        %interpolation in r-phi plane (worse but fast):
        convGridR       = sqrt(abs(gridX).^2 + abs(gridY).^2 + abs(gridZ).^2);
        convGridPhi     = atan(gridY./gridX);
        convGridTheta   = asin(gridZ./convGridR);
        %unwrap:
        qA = logical(logical((gridX >= 0)) .* logical((gridY<=0)));
        qB = logical(logical((gridX < 0)) .* logical((gridY<=0)));
        qC = logical(logical((gridX < 0)) .* logical((gridY>0)));
        qD = logical(logical((gridX >= 0)) .* logical((gridY>0)));
        convGridPhi(qA) = abs(convGridPhi(qA));
        convGridPhi(qB) = pi-convGridPhi(qB);
        convGridPhi(qC) = pi+abs(convGridPhi(qC));
        convGridPhi(qD) = 2*pi-convGridPhi(qD);
        convGridPhi(isnan(convGridPhi)) = 0;
        convGridTheta(isnan(convGridTheta)) = 0;
        
        xCart       = interp3(exp(gridR), gridPhi, gridTheta, xLogPol, ...
                        convGridR, convGridPhi, convGridTheta, interpMethod, extrapVal);
        
        
    end