I think I might know what you're referring to.
I'm guessing that you're using a version of MATLAB which is older than R2014b. For example, if I run your code in R2014a, and turn off the axes:
I get something that looks like this:
The rendering pipeline we used in earlier versions of MATLAB rounded coordinates to the nearest pixel, and in this case, the Y values 0 and 1e-15 map to adjacent pixels. This means that you see a ripple effect as the line oscillates between those two different rows of pixels.
We overhauled the rendering pipeline in R2014b. The new version doesn't represent pixel coordinates as integers. As a result, this case now looks something like this:
But you're also seeing the fact that the new renderering pipeline antialiases by default. You can turn that off using the GraphicsSmoothing property:
set(gcf,'GraphicsSmoothing','off')
and then you get this:
Assuming this is the issue you're seeing, then you're probably better off upgrading to a newer version of MATLAB than actually fiddling your data. If you have to use a version of MATLAB with integer pixel coordinates, you could try fiddling the Renderer property on the figure and see if one of the other renderers looks better, but I think that the differences will probably be pretty small.
Or perhaps I've guessed incorrectly. If you are using R2014b or later, then I would really like to know more about what you're seeing.
Best Answer