Why can't i plot a bar figure like this example?
2 次查看(过去 30 天)
显示 更早的评论
I want to plot a bar figure like this example,just take this example as a reference
My code is as below
x=[0 5 10 15 20 25]
life=[1344 423 133 41 12 3; 939 296 93 29 9 2]
L=bar(x,life);
xtips1 = L(1).XEndPoints;
ytips1 = L(1).YEndPoints;
labels1 = string(L(1).YData);
text(xtips1,ytips1,labels1,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
xtips2 = L(2).XEndPoints;
ytips2 = L(2).YEndPoints;
labels2 = string(L(2).YData);
text(xtips2,ytips2,labels2,'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
However the window always told me
Error using bar (line 142)
The length of X must match the number of rows of Y.
Error in yesharvest_vs_noharvest (line 5)
L=bar(x,life);
I am sure that the length of x and life are both "6",but the window still told me "The length of X must match the number of rows of Y". Where am i wrong?how do i modify it?
0 个评论
回答(1 个)
Nicolas B.
2019-11-8
If I transpose life like this:
x=[0 5 10 15 20 25]
life=[1344 423 133 41 12 3; 939 296 93 29 9 2]
L=bar(x,life');
Then I get that result:
Is it what you expect to get?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!