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

2 views (last 30 days)
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 Comment
dpb
dpb on 16 Sep 2014
Edited: dpb on 16 Sep 2014
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.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 16 Sep 2014
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.

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!