Effacer les filtres
Effacer les filtres

creating a histogram in a specific way

2 vues (au cours des 30 derniers jours)
alex
alex le 14 Déc 2011
hi, I want to make a histogram that gets a vector with values from the group (0 1 10 100, and creates a histogram that has one bin for each of those values and has the axis of x also sorted only for those values. I tried few things and nothing seems to work. I wand the bins in the same width.

Réponse acceptée

the cyclist
the cyclist le 14 Déc 2011
r = [0 0.1 0.2 0.3 1 2 3 10 20 30 40 50 60 70 80 90];
bins = [0 1 10 100];
count=hist(r,bins)
figure
bar(bins,count)
set(gca,'XTick',bins)
OR
r = [0 0.1 0.2 0.3 1 2 3 10 20 30 40 50 60 70 80 90];
bins = [0 1 10 100]
count=hist(r,bins)
figure
bar(1:4,count)
set(gca,'XTickLabel',bins)
  1 commentaire
the cyclist
the cyclist le 14 Déc 2011
If you use either of these solutions, do be aware of the issue that Sean brings up, which is whether you want the binning itself to be on a log scale. The binning in my solution is on a linear scale (even in the solution in which I display the results on what is essentially a log scale).

Connectez-vous pour commenter.

Plus de réponses (1)

Sean
Sean le 14 Déc 2011
Are you trying to bin on a log scale or are you trying to bin to arbitrary values?
If you are trying to do the first, you might try taking the log10() of all your input values and binning them linearly (i.e. less than 1 is negative, 1-9.9999 is is 0-1, 10-99.9999 is 1-2, etc.) You could round the values to fall into whichever bin you wanted.
  1 commentaire
Dr. Seis
Dr. Seis le 14 Déc 2011
Agreed... and then holding the bin "width" the same would make more sense.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by