How to make side-by-side bars with the histogram() function?

19 vues (au cours des 30 derniers jours)
the cyclist
the cyclist le 18 Mai 2015
Modifié(e) : Star Strider le 18 Mai 2015
When using the now-discouraged hist function to make histograms comparing two data sets, the default display was to put the bars of the two histograms side-by-side.
Now, with the new histogram function, the default behavior is to superimpose the two distributions, with some transparency.
What's the easiest way to get the old side-by-side behavior, while still using the new function?

Réponses (1)

Star Strider
Star Strider le 18 Mai 2015
Modifié(e) : Star Strider le 18 Mai 2015
I doubt that’s possible without some serious hacking.
A work-around:
A = randn(100,2);
[h1,edges] = histcounts(A(:,1), 10);
[h2,edges] = histcounts(A(:,2), 10);
figure(1)
ctrs = edges(1)+(1:length(edges)-1).*diff(edges); % Create Centres
bar(ctrs, [h1 ;h2]')

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by