MATLAB: How to set XTickLabel with equal width between the ticks?for 1,2, 127, and 128

tickticklengthwidthxtickxticklabelytick

width between 1 and 2 is small, similarly for 127 and 128. I need equal width for 1,2,127 and 128

Best Answer

Your graph is reproduced (with random y-values) by
x = [1 2 8:8:120 127 128];
y = rand(size(x));
figure, plot(x,y)
set(gca,'xtick',x)
Alternatively, you can plot y against the index of x:
xi = 1:19;
figure, plot(xi,y)
Now we can put the xticks at the index, but use x for the ticklabels:
set(gca,'xtick',xi,'xticklabel',x)
Not sure if this result is what you meant (or why it would be useful). Let me know if it helps.