Controlling the spacing between markers in a plot in a figure

How do I control the spaces between markers in a plot so that it although I am plotting say a 100,000 points but it shows markers at only sample points, and does not show markers when the plot drops between two points:
A sample is shown in figure below:
Thanks

 Accepted Answer

I'm not sure why my answer to your duplicate question at http://www.mathworks.com/matlabcentral/answers/57241#answer_69235 didn't work for you. Walter and I are both saying the same thing: plot a subset of your data:
plot(allYourData, 'r-');
hold on;
plot(allYourData(1:10:end), 'bo'); % Or can use scatter.
or something like that. You can pick them at random, or pick every 10th one like I did above or some other subsampling period.

4 Comments

plot(1:10:numel(allYourData), allYourData(1:10:end), 'bo')
to get the x axis correct relative to plot(allYourData)
you are right, but when I convert the y-scale to log, all these markers get mixed up and change position...the final plot should use the log or it wont be clear, so how do I go around this so that the markers are clear as the original linear plot?
Thanks
They don't get mixed up. How could that happen? It doesn't. You can go ahead and plot on a loglog, semilogx or semilogy and they won't change order. Everything is exactly where it should be. If you say they are not, then post code and a screenshot to prove it.
You are right...I just got my brain mixed up...lots of figures :(
Thanks man...your expertise is wonderful :)
Thanks for helping me...I appreciate it..

Sign in to comment.

More Answers (2)

plot() once without any markers on the line. Then scatter() the desired markers into place.

4 Comments

Do you think in that plot I gave as an example, he selected them at random? They dont look random
? I did not say anything about random ?
The plots you gave as examples look to me to be straight lines between the markers, as if only those points had been plotted, a marker for each point.
Yes, remember that plot(x,y) places the points at the given x locations. For example,
x = 0:1000:100000;
y = x.^2;
plot(x,y);
That will have an x axis from 0 to 100000 even though only 100 points are plotted.

Sign in to comment.

I wrote a function available at: https://www.mathworks.com/matlabcentral/fileexchange/37165-plotsparsemarkers Should work with MATLAB versions that have 'MarkerIndices' as well as the older ones.

Tags

Community Treasure Hunt

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

Start Hunting!