HOW DO I ADD SPACES IN BETWEEN THE POINTS OF X AXIS IN THE BAR GRAPH WHICH IS GENERATED BY MATLAB?

조회 수: 3 (최근 30일)
HOW DO I ADD SPACES IN BETWEEN THE POINTS OF X AXIS IN THE BAR GRAPH WHICH IS GENERATED BY MATLAB?
X AXIS VALUES ARE: x=[400 430 540 560 330 340 450 400 300 200 ];
Y = [6 4 7 9 1 2 6 1 1 9 5 8 8 1 7 7 1 1 8 1 5 8 8 5 9 1 1 5 1 2]; PLS REPLY
  댓글 수: 1
dpb
dpb 2014년 9월 16일
편집: dpb 2014년 9월 16일
How to unlock CAPLOCK Key???
How, specifically, did you generate a bar graph from the above data with differing length series?
>> x=[400 430 540 560 330 340 450 400 300 200 ];
Y = [6 4 7 9 1 2 6 1 1 9 5 8 8 1 7 7 1 1 8 1 5 8 8 5 9 1 1 5 1 2];
>> bar(x,Y)
Error using bar (line 55)
X must be same length as Y.
>>
Well, let's try to fixup that to see what get by default...
>> bar(x,Y(1:length(x)))
Error using bar (line 60)
XData cannot contain duplicate values.
>>
So, that isn't workable, either.
Looking at x somewhat more critically, it isn't in ascending order, either, which, while not impossible, isn't likely what would produce a desirable plot.
So, need a lot of work on the data underlying question it would seem, besides the edit.

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

답변 (1개)

Image Analyst
Image Analyst 2014년 9월 16일
Try this:
Y = [6 4 7 9 1 2 6 1 1 9 5 8 8 1 7 7 1 1 8 1 5 8 8 5 9 1 1 5 1 2];
x = 1 : length(Y); % Because yours was totally messed up.
bar(x, Y, 'BarWidth', 0.6);
Vary the BarWidth of 0.6 between 0 and 1 to get different spaces between the bars if you want to change it.

카테고리

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