How to plot discrete values on the x-axis.

Hello everybody,
I haven't figured out yet how can I plot discrete values along the x-axis. I need to plot for instance:
y= [10 1 2 3 20 22 20 10 14 12];
x = [89 89 89 89 89 89 89 90 91 10];

 Accepted Answer

Ameer Hamza
Ameer Hamza on 13 Oct 2020
Edited: Ameer Hamza on 13 Oct 2020
Try this
y = [10 1 2 3 20 22 20 10 14 12];
x = [89 89 89 89 89 89 89 90 91 10];
ax = axes();
plot(y, 'r+', 'MarkerSize', 10, 'LineWidth', 2)
ax.XTickLabel = string(x);

8 Comments

Thank you so much Ameer.
Just one other thing: let's assume that I have 10000 points along the x-axis, and most of them are "89". Is it possible to display just a small amount of such a digit instead of displaying all of them?
Yes, but you need to describe which one to select? Or do you want them to be selected randomly?
I would like to display all the values that appear once along the x-axis.
So you want to display just one point for all repeating values. For example, just one "89" on x-axis? What about y-value?
yes, i do.
As far as the y-values are concerned, i would like to display all of them
Run the following code. Is this what you want?
y = [10 1 2 3 20 22 20 10 14 12];
x = [89 89 89 89 89 89 89 90 91 10];
plot(x, y, 'r+', 'LineWidth', 2, 'MarkerSize', 10)
Nope, it was just an example. I am dealing with vectors much bigger than these.
But the same method will apply there.

Sign in to comment.

More Answers (0)

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!