The NAN replacement should have worked so long as the MatLab commands are setup correctly. I assume you have checked the NAN replacement worked correctly.
The display or not display is totally controlled by the MatLab code and once you have the outliners as NAN you do what you like with them inside MatLab.
A basic 2D plot is usually something like
plot(a(~isnan(a)),b(~isnan(a)));
I am either missing something or you should be googling "MatLab How to avoid to plot the NAN value?"
Perhaps a start point
Using and removing NaN in MATLAB plots » Stuart’s MATLAB Videos[
^]