This MATLAB function performs median filtering of the matrix A in two dimensions
while *ignoring* NaNs (based on discussions here
This function is quite useful, and it's fast. I find that nanmedfilt2 takes roughly twice as long as the medfilt2 function found in the image processing toolbox. That's not perfect, but it's faster than any other manual solutions I have tried. I recommend changing line 9 to sz=3 to match the default 3-by-3 neighborhood of medfilt2.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.