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?

 Respuesta aceptada

Daniel Shub
Daniel Shub el 25 de Sept. de 2011
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 comentarios

Henry
Henry el 25 de Sept. de 2011
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.
Daniel Shub
Daniel Shub el 25 de Sept. de 2011
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)
Henry
Henry el 25 de Sept. de 2011
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.
Daniel Shub
Daniel Shub el 25 de Sept. de 2011
Nope, I edited in repose to your comment. You cannot put formatted code in comments (which is a real pain).

Iniciar sesión para comentar.

Más respuestas (1)

Henry
Henry el 25 de Sept. de 2011
hmm, got a solution. When calling 'plot' for the second time, use 'LineStyle', 'none'.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Sept. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by