Is it possible to obtain both line and bars on the same graph?

1 vue (au cours des 30 derniers jours)
Pietro Fiondella
Pietro Fiondella le 28 Juin 2022
Commenté : Star Strider le 28 Juin 2022
I have these vectors Years, A,B i would like to obtain a single graph with both bar(Years,B) and plot(Years,A).
How can i do this?
Years=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
A=[-8.8000 -8.5211 -8.2421 -7.9632 -7.6843 -7.4053 -7.1264 -6.8475 -6.5685 -6.2896 -6.0107 -5.7318 -5.4528 -5.1739 -4.8950 -4.6160 -4.3371 -4.0582 -3.7792 -3.5003 -3.2214];
B=[-8.8000 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189];
%I can obtain separatly graphs:
plot(Years,A);
bar(Years,B);

Réponse acceptée

Star Strider
Star Strider le 28 Juin 2022
Use the hold function
Years=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
A=[-8.8000 -8.5211 -8.2421 -7.9632 -7.6843 -7.4053 -7.1264 -6.8475 -6.5685 -6.2896 -6.0107 -5.7318 -5.4528 -5.1739 -4.8950 -4.6160 -4.3371 -4.0582 -3.7792 -3.5003 -3.2214];
B=[-8.8000 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189];
%I can obtain separatly graphs:
figure
plot(Years,A)
hold on
bar(Years,B)
hold off
.
  2 commentaires
Pietro Fiondella
Pietro Fiondella le 28 Juin 2022
Thank you Star Strider!
Star Strider
Star Strider le 28 Juin 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by