MATLAB: Normalized 2D cross correlation

cross correlationMATLAB

I am trying to utilize the c=normxcorr2(template,A) function for two surface plots and I am running into the following errors;
??? Error using ==> iptcheckinput Function NORMXCORR2 expected its second input, A, to be finite.
Error in ==> normxcorr2>ParseInputs at 232 iptcheckinput(A,{'logical','numeric'},{'real','nonsparse','2d','finite'},mfilename,'A',2)
Error in ==> normxcorr2 at 55 [T, A] = ParseInputs(varargin{:});
Both matrices are the Z coordinates for the plots and and I can find the template in A and yes A is bigger than template. Matrix A is 427×249 and template is 299×149. The elements in both matrices range from -50 to +75 and also have NaN as fill elements.
I was wondering if someone knows whether it is appropriate to use this function for such manipulation if not can you help me to perform the 2D cross correlation for two surface plots?
Thanks, Shayan

Best Answer

No. normxcorr2 requires that the elements be finite, i.e. not nan and not inf. The normalized cross correlation algorithm is not a difficult one ( wikipedia:normalized X-correlation )
I would recommend coding it yourself using functions that ignore nans ( nansum, nanmean, nanstd ). If you don't have the stats toolbox that contains these there is a nan-suite on the FEX.
Related Question