Can I put markers on only some of the points in my plot?

It was mentioned that "the request for a built-in MATLAB command to do this automatically has been forwarded to our development staff for consideration for a future version of MATLAB."
Is this feature available now in the latest Matlab?

 Accepted Answer

To my knowledge it has not happened yet. The work round seems pretty good to me.
figure;
XVec = 0:(pi/2):10*pi;
YVec = sin(XVec);
plot(XVec, YVec);
hold on;
plot(XVec(1:4:end), YVec(1:4:end), '+');
figure;
XVec = 0:(pi/16):10*pi;
YVec = sin(XVec);
plot(XVec, YVec);
hold on;
plot(XVec(1:8:end), YVec(1:8:end), '+');
notice the second plot is just '+' and not '-+'.

4 Comments

Sorry, but the work round in that link is awful to me.
> plot(XVec,YVec)
> plot(XVec(1:4:end),YVec(1:4:end), '+')
Since 'plot' just draws a line between two adjacent points in the data array, the above two plots are different and may *not* overlap. Just imagine XVec and YVec is a sin function evaluated at 0, pi/2, pi, 3*pi/2, 2*pi, ... Then the second plot will just give a flat horizontal line.
Have you tried it (see my edit). The first plot, plots a "line" which linearly interpolates between the data points in (XVec, YVec). This line will go through all the data points in (XVec, Yvec). The second plot will not plot a line. It will just plot symbols on every 4th point in (XVec, Yvec)
Thanks Daniel. Somehow you code segment showed up only 2 minutes ago, though I saw the first sentence in your answer right after it was posted.
Nope, I edited in repose to your comment. You cannot put formatted code in comments (which is a real pain).

Sign in to comment.

More Answers (1)

hmm, got a solution. When calling 'plot' for the second time, use 'LineStyle', 'none'.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!