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일

1 개 추천

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.

댓글 수: 2

madhan ravi
madhan ravi 2018년 11월 15일
+1 always a saviour!
Star Strider
Star Strider 2018년 11월 15일
@Madhan — Thank you!

댓글을 달려면 로그인하십시오.

madhan ravi
madhan ravi 2018년 11월 15일
편집: madhan ravi 2018년 11월 15일

0 개 추천

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

I get an error
Undefined function or variable 'xticklabels'.
I am using MATLAB R2016a-student use
Another error
Undefined function or variable 'xticks'.
madhan ravi
madhan ravi 2018년 11월 15일
my suggestion is to upgrade to 2016b which makes your work a lot more easier and faster
can you provide an answer that works for 2016a. I cannot update to 2016b by myself.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

댓글:

2018년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by