Effacer les filtres
Effacer les filtres

How to draw a histogram with different bin colors based on value?

5 vues (au cours des 30 derniers jours)
Robin Li
Robin Li le 16 Mai 2019
Réponse apportée : KSSV le 16 Mai 2019
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!

Réponse acceptée

KSSV
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')

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by