Error using bar (line 172) X must be same length as Y.

i am trying to plot a bar graph as illustrated in https://nl.mathworks.com/help/matlab/ref/bar.html
with the example code:
x = 1990;
y = [10 20 30];
bar(x,y)
but I got the error as menitioned in the Title.
is there any solution for it?

3 Comments

I have the same problem, using MATLAB R2018a. It does not make any sense for an example code not to work!
Same for me, using R2017b. I copied the example code exactly and got the same error.
Hi dear brother I hope you find the answer, if yes let me know it please, and thank you

Sign in to comment.

Answers (1)

Transpose y:
x = 1990;
y = [10 20 30]';
bar(x,y)

Products

Release

R2018b

Tags

Asked:

on 11 Dec 2019

Commented:

on 19 Mar 2022

Community Treasure Hunt

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

Start Hunting!