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

5 ビュー (過去 30 日間)
Robin Li
Robin Li 2019 年 5 月 16 日
回答済み: KSSV 2019 年 5 月 16 日
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!

採用された回答

KSSV
KSSV 2019 年 5 月 16 日
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 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by