3

How can I set the x axis label as a vector? For example, if I do plot(1:5), the x axis label is [1, 2, 3, 4, 5]. I'd like to set it to a vector, e.g. [1 4 5 7 10]. Note that the vector's size may be huge, so doing it manually is not acceptable.

dalibocai
  • 2,289
  • 5
  • 29
  • 45

2 Answers2

2

I believe this is what you want.

y = 1:5;
x = [1 4 5 7 10];
plot(y);
set(gca,'XTickLabel',x);
Phonon
  • 12,549
  • 13
  • 64
  • 114
1

you can do this by sending plot two vectors: one for x and one for y.

plot([1 4 5 7 10], 1:5);
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319