I want to make a plot that discontinues at one point using Matlab.
This is what the plot looks like using scatter
:
However, I would like to the plot to be a smooth curve but not scattered dots. If I use plot
, it would give me:
I don't want the vertical line.
I think I can break the function manually into two pieces, and draw them separately on one figure, but the problem is that I don't know where the breaking point is before hand.
Is there a good solution to this? Thanks.
To find the jump in the data, you can search for the place where the derivative of the function is the largest:
One way to plot the function would be to set that point to
NaN
and plotting the function as usual:This comes with the disadvantage of losing a data point. To avoid this, you could add a data point with value
NaN
in the middle:Another solution would be to split the vectors for the plot:
All ways so far just handle one jump. To handle an arbitrary number of jumps in the function, one would need some knowledge how large those jumps will be or how many jumps there are. The solution would be similar though.