필터 지우기
필터 지우기

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 CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by