How to include different values for x-ticks

1 次查看(过去 30 天)
Hi,
Suppose the following for X and Y, where x and y are some parameters measured from year 2000-2004.
x=[2 5 3 7 10]
y=[10 13 15 7 3]
On the figure I make, I want to put years (2000, ...,2004) rather than 1,....,5. How can I do that?
Thanks,
Thishan

回答(2 个)

Star Strider
Star Strider 2018-11-15
Try this:
x=[2 5 3 7 10];
y=[10 13 15 7 3];
yrs = 2000:2004;
t = datenum([yrs' zeros(numel(yrs),4) ones(size(yrs'))]);
figure
plot(t, x, t, y)
datetick('x', 'yyyy', 'keeplimits')
That will plot the years correctly.

madhan ravi
madhan ravi 2018-11-15
编辑:madhan ravi 2018-11-15
see release notes for tick labels available from 2016b
x=[2 5 3 7 10];
y=[10 13 15 7 3];
plot(x,y)
xticks(linspace(x(1),x(end),4)) %likewise for y-axis
xticklabels({'2001','2002','2003','2004'})
  4 个评论
madhan ravi
madhan ravi 2018-11-15
my suggestion is to upgrade to 2016b which makes your work a lot more easier and faster
Thishan Dharshana Karandana Gamalathge
can you provide an answer that works for 2016a. I cannot update to 2016b by myself.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by