Binning data into 1000 bins between values

5 views (last 30 days)
Tim Fulcher
Tim Fulcher on 21 Sep 2021
Commented: Steven Lord on 21 Sep 2021
Hi all,
I have 75,000 values and I'd like to bin them into 1000 bins between 0.985 and 1.030. Is this possible and if so how?
Regards
Tim

Answers (1)

Image Analyst
Image Analyst on 21 Sep 2021
Description
Y = discretize(X,edges) returns the indices of the bins that contain the elements of X. The jth bin contains element X(i) if edges(j) <= X(i) < edges(j+1) for 1 <= j < N, where N is the number of bins and length(edges) = N+1. The last bin contains both edges such that edges(N) <= X(i) <= edges(N+1).
[Y,E] = discretize(X,N) divides the data in X into N bins of uniform width, and also returns the bin edges E.
[Y,E] = discretize(X,dur), where X is a datetime or duration array, divides X into uniform bins of dur length of time. dur can be a scalar duration or calendarDuration, or a unit of time. For example, [Y,E] = discretize(X,'hour') divides X into bins with a uniform duration of 1 hour.
[___] = discretize(___,values) returns the corresponding element in values rather than the bin number, using any of the previous input or output argument combinations. For example, if X(1) is in bin 5, then Y(1) is values(5) rather than 5. values must be a vector with length equal to the number of bins.
  2 Comments
Tim Fulcher
Tim Fulcher on 21 Sep 2021
Hi Image Analyst,
thanks for replying. I'll try this and get back to you.
Regards
Tim
Steven Lord
Steven Lord on 21 Sep 2021
If you also want the counts of how many elements fall into each bin I'd use histcounts with three outputs.

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!