Even binned histogram to uneven bins?
Afficher commentaires plus anciens
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
le 18 Sep 2020
0 votes
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
le 18 Sep 2020
Star Strider
le 18 Sep 2020
Star Strider
le 19 Sep 2020
Try something like this:
x = logspace(-4, 3, 250)/2; % Simulate Data
y = (x+2).*exp(-0.075*x);
y = y/max(y); % Simulate Data
figure
plot(x, y, '-p') % Plot Simulated Data
grid
dx = diff(x); % X-Vector Differences
edgs = logspace(log10(min(dx)), log10(max(dx)), 51)/10; % Calculate Edges For 50 Bins
figure
histogram(y, edgs) % Resulting Histogram
Make appropriate changes to get the result you want.
Tim Fulcher
le 19 Sep 2020
Star Strider
le 19 Sep 2020
My pleasure!
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
le 18 Sep 2020
Tim Fulcher
le 19 Sep 2020
Modifié(e) : Tim Fulcher
le 19 Sep 2020
0 votes
Tim Fulcher
le 19 Sep 2020
Modifié(e) : Tim Fulcher
le 19 Sep 2020
0 votes
Tim Fulcher
le 21 Sep 2020
Modifié(e) : Tim Fulcher
le 21 Sep 2020
0 votes
3 commentaires
Star Strider
le 21 Sep 2020
Noted!
Have fun!
Tim Fulcher
le 21 Sep 2020
Star Strider
le 21 Sep 2020
My pleasure!
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


