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

2 次查看(过去 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 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by