# How to remove singularit​ies/discon​tinuities on 3D plots in Matlab?

I want to plot some functions f(x,y) including singularities. For example; f(x,y)=tan(x-y)

• In Matlab, when I run the following code

syms x y; func=@(x,y) tan(x-y); fsurf(@(x,y) func(x,y), [-4 2 -1 1]);

I get

• In Mathematica, when I plot the same function, I can remove the discontinuities using Exclusions -> "Singularities"

My question: In MATLAB, how to remove vertical asymptote lines in Matlab's figure like Mathematica?

-How to find the asymptote lines in Matlab. After finding the asymptote, maybe we make it invisible in the plot.

• Did you try clipping the z value in Matlab to e.g. (staying with your Mathematica example) [-5, 5] ? If you need it for a general case, you could try to clip the values to some multiplicity of the mean value(assuming the mean is not too corrupted). Jan 6 at 9:23
• That will not help because MATLAB interpolates across the discontinuity. The singularities should be detected (as in Mathematica) and the numerical data could be plotted piecewise. Jan 6 at 10:50