If the goal is to remove all of the markers except for the 'outer' ones, then try this. This should be relatively generic (independent of the size specified by nx and ny), if not elegant.
Replace this line:
with these two lines:
plot(X, Youter, 'ro', 'MarkerFaceColor', [1, 0.6, 0.6])
If I misinterpreted your goals, post a comment making them more clear.