I have a 500x500 matrix of numbers and NaN values. I want to determine the average correlation coefficient between a pixel and its nearest 8 neighbors (3x3 grid) while omitting NaN values from the calculation. My output will then be a 500x500 matrix of correlation coefficients and NaN values. When calculating values on the edge of the matrix, I will use however many neighbors surround the pixel of interest in the 3x3 grid.
Any ideas on how to do this? I am aware of the corrcoef command, but I don't know how to make it work for the comparison of multiple numbers.
Thanks in advance.
MATLAB Version: 126.96.36.1994444 (R2018b)