How can I plot histograme of a vector with four values independant?
v=[1; 2;0;1]

 채택된 답변

Adam Danz
Adam Danz 2020년 1월 8일
편집: Adam Danz 2020년 1월 8일

0 개 추천

If those values describe the bar height, you could use bar(___,width) and specify the width of the bars as 1 to resemble a histogram.
v=[1; 2;0;1];
bar(v,1) % figure shown below
Alternatively, you can use histogram('BinEdges',edges,'BinCounts',counts) which specifies the bin edges.
histogram('BinEdges',.5 : 1 : 4.5,'BinCounts',v)

댓글 수: 4

Mira le
Mira le 2020년 1월 8일
How can we add the color option
Adam Danz
Adam Danz 2020년 1월 8일
You'll need to be more specific.
Mira le
Mira le 2020년 1월 8일
each bar of the histogramme with a different color
Adam Danz
Adam Danz 2020년 1월 8일
편집: Adam Danz 2020년 1월 8일
If you're using the bar() approach,
b = bar(v,1);
b.FaceColor = 'flat';
b.CData = [1 0 0; 0 1 0; 0 0 1; 1 1 0]; % set color of each bar
If you're using the histogram() approach, you'll need to loop through each value of v and plot each bar separately (this is not recommended).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

제품

태그

질문:

2020년 1월 8일

편집:

2020년 1월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by