Eduardo
Eduardo

Reputation: 7131

Changing how many tick labels on a plot in MATLAB

I have 3 arrays,

y = [1,4,6,8,2,5,......];
x = [1,2,3,4,5,6,......];
xlabel = {'label1','label2','label3',........};

where each element in xlabel is the label for each element of the x array.

I am plotting this using:

plot(x,y);
set(gca,'xtick',x,'xticklabel',xlabel);

But because my arrays hold thousands of elements I am getting a black bar as a label because MATLAB is printing every label (see image).

Note different data is used that has been povided

How do I change this so MATLAB only prints a select few of my xlabels?

Upvotes: 1

Views: 2757

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112659

You can do for example:

selected = 1:100:numel(x); % change the "100" as desired
set(gca,'xtick',x(selected),'xticklabel',xlabel(selected));

Upvotes: 1

Related Questions