How to draw a histogram with different bin colors based on value?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Suppose I have a vector of [-2, 3, 1, 2, -1, -2], and I want to create a histogram that with red bins when the element of vector>0 and blue bins when <0.
How could I do that?
Thank you!
0 commentaires
Réponse acceptée
KSSV
le 16 Mai 2019
v = [-2, 3, 1, 2, -1, -2] ;
x = 1:length(v) ;
figure
hold on
bar(x(v<0),v(v<0),'r')
bar(x(v>0),v(v>0),'b')
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Histograms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!