MATLAB Answers


How to change the x axis labels of a plot so that they only show integer values

Asked by AStar
on 15 Nov 2019 at 2:26
Latest activity Edited by AStar
on 15 Nov 2019 at 2:39
Id like to make the x axis labels so that it just shows 1,2,3,4,5,6. But id like to make sure this is general so in my code if the user were to input 10 years lets say, the x axis labels would be 1,2,3,4,5,6,7,8,9,10.


What datatype is the x axes? duration()? Or is it double and you are using datetick() ?
the x values are a vector. Im not sure what you mean by duration, double and datetick. I am a beginner to a matlab, so I dont know what terminology youre referring to.

Sign in to comment.


1 Answer

Answer by Walter Roberson
on 15 Nov 2019 at 2:28

ax = gca;
ax.Xticks = unique( round(ax.XTicks) );

  1 Comment

Hi, thanks for your response, however, it doesnt seem to work. What is ax? Is that the name of the x vector?Matlab also says that it doesnt recognize XTicks.

Sign in to comment.