How can I change x axis to months format
ex: Jan instead of 1, and Feb instead of 2

9 件のコメント

Paresh yeole
Paresh yeole 2020 年 5 月 3 日
Use xticklabels
xticks(1:12)
xticklabels({'Jan','Feb','Mar',...)
Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
I tried to apply it in my code but it does not work:
months=1:12
A=[118.00575,141.14832,215.06911,244.017855,259.748722,...
316.264968,312.004731,284.158783,233.389667,173.581341,120.328931,83.5528434];
B=[125.005376,153.263393,208.340054,265.275,311.823925,354.2625,350.813172,...
315.857527,276.381944,216.389785,159.719444,118.275538];
C=[150.623337096774,188.411076934524,251.094712768817,286.411819027778,314.503991397849,...
344.678580972222,334.548557930107,312.403280510752,267.2707425,215.908282392473,170.403158611111,145.476231989247];
plot(months,A)
hold on
plot(months,B)
plot(months,C)
Paresh yeole
Paresh yeole 2020 年 5 月 3 日
The vectors A,B,C are not of same length.
Size of vector B is 1*13.
Also, vector C is not defined correctly.
Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
A,B, and C are the same length which is 1*12
Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
A=[118.00575,141.14832,215.06911,244.017855,259.748722,316.264968,312.004731,284.158783,233.389667,173.581341,120.328931,83.5528434];
B=[125.005376,153.263393,208.340054,265.275,311.823925,354.2625,350.813172,315.857527,276.381944,216.389785,159.719444,118.275538];
C=[150.623337096774,188.411076934524,251.094712768817,286.411819027778,314.503991397849,344.678580972222,334.548557930107,312.403280510752,267.2707425,215.908282392473,170.403158611111,145.476231989247];
Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
basically i's B=[1256,1533,208,265,311,354,350,315,276,216,159,118]; i've removed the Decimal numbers
Paresh yeole
Paresh yeole 2020 年 5 月 3 日
It works:
plot(months,A)
hold on
plot(months,B)
plot(months,C)
xticks(1:12)
xticklabels({'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'})
Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
months=1:12
A=[118.00575,141.14832,215.06911,244.017855,259.748722,316.264968,312.004731,284.158783,233.389667,173.581341,120.328931,83.5528434];
B=[125.005376,153.263393,208.340054,265.275,311.823925,354.2625,350.813172,315.857527,276.381944,216.389785,159.719444,118.275538];
C=[150.623337096774,188.411076934524,251.094712768817,286.411819027778,314.503991397849,344.678580972222,334.548557930107,312.403280510752,267.2707425,215.908282392473,170.403158611111,145.476231989247];
plot(months,A)
hold on
plot(months,B)
plot(months,C)
xticks(1:12)
xticklabels({'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'})
% the result is:
Undefined function 'xticks' for input arguments of type 'double'.
Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
Oh the problem was i used matlab 2013 !
thank you!

サインインしてコメントする。

 採用された回答

Ajay Kumar
Ajay Kumar 2020 年 5 月 3 日

0 投票

Use xticklables for eg:
x = linspace(0,12);
y = x.^2;
plot(x,y)
xticks([0:1:12])
xticklabels({'','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'})

5 件のコメント

Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
I tried to apply it in my code but it does not work:
months=1:12
A=[118.00575,141.14832,215.06911,244.017855,259.748722,...
316.264968,312.004731,284.158783,233.389667,173.581341,120.328931,83.5528434];
B=[125.005376,153.263393,208.340054,265.275,311.823925,354.2625,350.813172,...
315.857527,276.381944,216.389785,159.719444,118.275538];
C=[150.623337096774,188.411076934524,251.094712768817,286.411819027778,314.503991397849,...
344.678580972222,334.548557930107,312.403280510752,267.2707425,215.908282392473,170.403158611111,145.476231989247];
plot(months,A)
hold on
plot(months,B)
plot(months,C)
Ajay Kumar
Ajay Kumar 2020 年 5 月 3 日
編集済み: Ajay Kumar 2020 年 5 月 3 日
xticks(1:12)
xticklabels({'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'})
Add these 2 lines in the end
Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
Undefined function 'xticks' for input arguments of type 'double'. this is the result
Ajay Kumar
Ajay Kumar 2020 年 5 月 3 日
Which line is the error? I tried it I got the output.
Ibrahim AlZoubi
Ibrahim AlZoubi 2020 年 5 月 3 日
Oh the problem was i used matlab 2013 !
thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLabels and Annotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by