How can I plot discrete x-axis values?

How can I choose which x axis values are displayed? I am plotting a bar graph with x-axis values of [1,2,3,5,7,10] and I want there to be equal spacing between the bars.
If I use bar() and plot() there is a gap between bars because the x-values 4,6,8,9 are not in the data.

 採用された回答

jgg
jgg 2016 年 1 月 19 日

2 投票

Try this
x = [1,2,3,5,7,10]; %your bins
y = rand(1,6); %your data
numbins = size(x,2);
x1 = [1:numbins];
bar(x1,y)
set(gca,'XTickLabel',x);

2 件のコメント

Kyle West
Kyle West 2016 年 1 月 19 日
Perfect, thank you!
Jaime Dantas
Jaime Dantas 2020 年 10 月 22 日
You saved my day! Believe you or not, this problem is quite hard to solve.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

質問済み:

2016 年 1 月 19 日

コメント済み:

2020 年 10 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by