# Why can't i plot a bar figure like this example?

1 visualizzazione (ultimi 30 giorni)
yang-En Hsiao il 8 Nov 2019
Risposto: Nicolas B. il 8 Nov 2019
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Nicolas B. il 8 Nov 2019
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Bar Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by