MATLAB: How to make surface plots with many NaN’s in the matrix

3d plotscolormapMATLABnansurfsurface

So I have a matrix of data that I'm trying to plot on the z-axis of a surface plot. However, it is populated with NaN's where I do not want data points to be plotted. This results in surface plots that look like this:
MATLABerror.jpg
It looks like a surface should fit over those points, but surf is having a hard time filling in the areas with color. I'm doing
surf(p1,q1,F1,'EdgeColor','interp','FaceColor','interp')
where F1 is my matrix with NaN's. Any ideas on how to make this work?

Best Answer

The fillmissing (link) function may be what you want. See specifically Matrix with Missing Endpoints (link).