How can I plot discrete x-axis values?

조회 수: 15 (최근 30일)
Kyle West
Kyle West 2016년 1월 19일
댓글: Jaime Dantas 2020년 10월 22일
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일
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개)

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by