MATLAB: How to graph using surf with an interval

MATLABsurf

I have the following:
[x,y] = meshgrid(-2:.2:2); z = x .* exp(-x.^2 – y.^2); surf(x,y,z)
and I am trying to get the following:
How do I graph it to exclude the mid section like that?

Best Answer

NaN is your friend here:
NOTE You have to use two separate vectors in your meshgrid call to create this effect, not the single vector you have in the code you posted. One vector is the one in your code. You have to create the second one with the gap.