function Y = callLocalInterp(X, V, Xq, method, extrapval, noX)
%CALLLOCALINTERP makes a call to the appropriate core MATLAB interp-family
%function and returns the result.
% X and Xq are cell arrays containing, X, Y, Z,... and Xq, Yq, Zq,...
% respectively.

%   Copyright 2021 The MathWorks, Inc.

interpDimensionality = numel(Xq);
switch interpDimensionality
    case 1
        interpFunHandle = @interp1;
    case 2
        interpFunHandle = @interp2;
    case 3
        interpFunHandle = @interp3;
    otherwise
        interpFunHandle = @interpn;
end

if nargin>=6 && noX
    if isempty(extrapval) || strcmpi(extrapval, 'none')
        Y = interpFunHandle(V, Xq{:}, method);
    else
        Y = interpFunHandle(V, Xq{:}, method, extrapval);
    end
elseif isempty(extrapval) || strcmpi(extrapval, 'none')
    Y = interpFunHandle(X{:}, V, Xq{:}, method);
else
    Y = interpFunHandle(X{:}, V, Xq{:}, method, extrapval);
end
end
