Combine histograms in a bar plot
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm using this code to represent my data as wanted:
histogram('BinEdges', 0:20, 'BinCounts',myArrayOfDouble,'LineWidth', 0.5)
but now i want to show several of these at the same figure, and the solution with figure made by user the cyclist in thread under accepted answer here is preferable:
But how? (I don't want the histogram function where data gets put in bins according value, but have to use code shown to get the figure as wanted.) Sorry for poor explaining. Hope someone knows a trick for this.
0 commentaires
Réponses (1)
Adam Danz
le 7 Mai 2021
Modifié(e) : Adam Danz
le 11 Mai 2021
I think what you want is to produce a histogram with data that already contains the bin counts rather than using the histogram function to count the number of values within each bin.
If my interpretation is correct, use the syntax, histogram('BinEdges',edges,'BinCounts',counts)
Example
binEdges1 = [0 1 2 3 4 5]; % 5 bins, 6 edges
counts1 = [9 8 7 6 5]; % counts
binEdges2 = [2 3 4 5 6 7];
counts2 = [5 6 7 8 9];
figure()
hold on % <-- important
histogram('BinEdges',binEdges1,'BinCounts',counts1)
histogram('BinEdges',binEdges2,'BinCounts',counts2)
Or perhaps you want the grouped option with bar plots,
bar([hcx(:),hcy(:)],'grouped')
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!