Clear Filters
Clear Filters

How can I see the right labels on x-axis?

2 views (last 30 days)
Hello everyone,
why do I got this error and I can't see the right labels on my plot?
Can anyone help me please?
Thank you.
NEW= B * 10 * 0.35;
C=datetime(C,'InputFormat','dd MMM yyyy'); %convert to datetime format
newTicks = datetime({'2000','2002','2004','2006','2008','2010','2012','2014','2016','2018'},'InputFormat','u');
Error using xticks (line 33)
Tick values must be a vector of increasing numeric values.
hold on

Accepted Answer

Star Strider
Star Strider on 9 Dec 2021
Without downloading the .mat file and running the entire code, this seems to work —
newTicks = datetime({'2000','2002','2004','2006','2008','2010','2012','2014','2016','2018'},'InputFormat','yyyy', 'Format','yyyy');
plot(newTicks, rand(size(newTicks)))

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 9 Dec 2021
You have not plotted anything to this point.
newTicks = datetime({'2000','2002','2004','2006','2008','2010','2012','2014','2016','2018'},'InputFormat','u');
You create a vector of datetime values, but nothing has been plotted yet
You tell xticks to use a series of floating point numbers. Because you have not plotted anything yet, this use of floating point numbers for the tick positions tells MATLAB that the x axes should be created as a numeric axes (not as a datetime or map or polar axes)
You have already created ticks, so this command would be to change the ticks to something else. But the previous xticks() call forced the axes to numeric, and this xticks() is trying to use datetime ticks. You cannot use datetime() ticks on a numeric axes.
... Just skip the xticks() giving the numeric values.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!