How to change my x axis value

32 views (last 30 days)
Hello. Is it possible for me to change my x axis value? My data is from 1982-2017. I plot and came out like this:
but I want it to be like this:
The x-axis showing the year.
Thank you in advance!

Accepted Answer

the cyclist
the cyclist on 14 Jan 2021
Edited: the cyclist on 14 Jan 2021
It would be helpful if you posted your data, so we know exactly how it is stored (e.g. do you just have the years stored as numeric values, or do you have whole dates stored as datetime type?).
But, it looks like you did
which will default to plotting x = 1:N, where N is the number of data points in y.
Instead, you should
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria on 15 Jan 2021
YES! Thank you very much sir!

Sign in to comment.

More Answers (1)

WalterWhite on 14 Jan 2021
the cyclist
the cyclist on 14 Jan 2021
Edited: the cyclist on 14 Jan 2021
To be clear about what I was saying, if OP has plotted with one variable, like this
rng default
they will get the plot
and this plot will not be fixed by adding
which will create ticks at x-axis positions 1980:5:2020, and the plot will then look like this
because the data are at 1:9, and the ticks are far away to the right at 1980-2020. Instead, they could use
to change the labels of the existing tick marks at 1:9 into 1980:5:2020, yielding
But I think it is fundamentally better to actually plot the date data, as suggested in my solution.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!