フィルターのクリア

Simple 2D plot; Any way I can use String for xtick?

24 ビュー (過去 30 日間)
Joon Jeon
Joon Jeon 2012 年 3 月 21 日
I am going to put four ticks on horizontal axis such as
t=1:1:4
However, actually, each number implies scenarios. So, instead of using that, I'd like to use such as
t=['Scenario1', 'Scenario2', 'Scenario3','Scenario4'];
y=[33 55 66 77];
plot(t,y)
However, as expected, the result shows an error message saying that t is not going to be converted to number.
Is there any way I can put these strings as x tick?

採用された回答

Wayne King
Wayne King 2012 年 3 月 21 日
Hi, Yes, there are a number of ways. Here is one:
y = [33 55 66 77];
plot(y)
set(gca,'xtick',1:4);
set(gca,'xticklabel',{'Scenario1', 'Scenario2', 'Scenario3','Scenario4'},'fontsize',8)
  1 件のコメント
Joon Jeon
Joon Jeon 2012 年 3 月 21 日
Thanks, it works!

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

その他の回答 (1 件)

Joon Jeon
Joon Jeon 2012 年 3 月 21 日
I added
xlim([0.8, 4,2]);
to make it look neater.

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by