![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260440/image.png)
How to plot histogramme?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mira le
am 8 Jan. 2020
Bearbeitet: Adam Danz
am 8 Jan. 2020
How can I plot histograme of a vector with four values independant?
v=[1; 2;0;1]
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 8 Jan. 2020
Bearbeitet: Adam Danz
am 8 Jan. 2020
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260440/image.png)
4 Kommentare
Adam Danz
am 8 Jan. 2020
Bearbeitet: Adam Danz
am 8 Jan. 2020
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).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!