0
$\begingroup$

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

enter image description here

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

enter image description here

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.

$\endgroup$
2
  • 1
    $\begingroup$ 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). $\endgroup$
    – Dan Doe
    Jan 6, 2022 at 9:23
  • $\begingroup$ 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. $\endgroup$ Jan 6, 2022 at 10:50

1 Answer 1

3
$\begingroup$

MATLAB doesn’t plot where there are NaNs, so you can replace some of your data with NaNs to make a clean jump.

I don’t know which is a bigger lie, a clean jump or a strange wiggle. That’s up to your eye and values.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.