Even binned histogram to uneven bins?

8 vues (au cours des 30 derniers jours)
Tim Fulcher
Tim Fulcher le 18 Sep 2020
Commenté : Star Strider le 21 Sep 2020
Hi all,
I have a csv file consisting of 256 bins each of 2mm width and I need to convert to uneven bins. 32 bins of 2mm width, 48 of 4mm width and 4 of 8mm depth. I would prefer not to use the bin edges as reference but rather the mid-point of the bins for reference but, if I need, I'll use the bin edges.
Can this be done using Matlab?
Apologies for not replying to my earlier posts.
Regards
Tim

Réponses (5)

Star Strider
Star Strider le 18 Sep 2020
If you are using the histogram function, you can specify the bind widths using the edges option. See Specify Bin Edges of Histogram for a relevant example. Remeber that there is one more edge than the number of bins, so each bin must be defined as two specific bin edges. The histcounts function works similarly, if you are using that instead.
  5 commentaires
Tim Fulcher
Tim Fulcher le 19 Sep 2020
Thanks SS. I'll try that when I get the time (see post below. Bastard employers want their pound of flesh. Nah, they're good and support me but I still need to do real work).
T
Star Strider
Star Strider le 19 Sep 2020
My pleasure!

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 18 Sep 2020
Let's make some sample data.
x = randi(255, 1, 1e5);
Use bin edges that are the squares of the integers between 1 and 16. Each bin but the last contains its left edge but not its right (this is the default behavior), the last contains both its edges.
h = histogram(x, (1:16).^2);
To make it easier to see that the bin edges are at those specific values, set the ticks.
xticks((1:16).^2)
Check that MATLAB reports that the bins are not of uniform width.
h.BinWidth
  1 commentaire
Tim Fulcher
Tim Fulcher le 18 Sep 2020
Thanks Steven, as per the previous reply I'll give that a go.

Connectez-vous pour commenter.


Tim Fulcher
Tim Fulcher le 19 Sep 2020
Modifié(e) : Tim Fulcher le 19 Sep 2020
I tried the histogram option you guys suggested. It's better but not quite there.
Two attachments: what it should look like and what histogram is throwing out. The latter looks like it's taking the average of the data for those bin sizes and putting that average into all the bins of that size. I'll have a look at the data in the next few days (sorry, I'm a part time PhD student and have to earn my crust to pay the uni fees) and see whether that is the case.
And yes, if you're interested, it is a Bragg Peak.
T

Tim Fulcher
Tim Fulcher le 19 Sep 2020
Modifié(e) : Tim Fulcher le 19 Sep 2020
Here's the result from histogram:

Tim Fulcher
Tim Fulcher le 21 Sep 2020
Modifié(e) : Tim Fulcher le 21 Sep 2020
Hi guys,
eventually I went for hard coded. Tedious and inflexible but I think, in this case it might be the best solution.
Thanks very much for your help.
T
  3 commentaires
Tim Fulcher
Tim Fulcher le 21 Sep 2020
Thanks SS. And again for your help.
T
Star Strider
Star Strider le 21 Sep 2020
My pleasure!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices 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!

Translated by