How to sort multiple arrays into bins generated by another array?
Show older comments
Dear community,
Below is a worked example representing my scenario and leads into the questions that I have.
I start with 3 arrays which are sorted with respect to C. The elements corresponding to each index are a pair (e.g the first element from arrays belong together such that the first element would be (1,10,-0.7)
A = [1 2 3 4 6 5 9 8 7]
B = [10 12 10 8 1 1 3 5 22]
C = [-0.7 -0.5 -0.4 -0.3 0 0.1 0.2 0.5 0.7]
I then specified the number of bins I would like:
numBins = 4
And I used histcounts to see how my data from C are sorted in the bins:
[N,edges]=histcounts(C,numBins)
Finally, I used histogram in a similar manner to visualise my results:
h = histogram(C,numBins)
The results I got were logical and appropriate for my scenario. For this example I get:
N = [1,3,3,2] & edges = [-0.9,-0.5,-0.1,0.3,0.7]
These are the questions that arise:
1) How can I see which elements from the C array are in each bin? For example, in which bin do C(1) and C(2) belong?
2) How can I get another array with as many elements as the number of Bins and each element is an array itself and includes all values from C which apply there? For example, D = [array1 array2 array3 array4].
3) How can I put the corresponding elements in the A and B arrays in the same bins? For example, A(1) and B(1) grouped with the C(1)
Thank you for taking the time to read my question. I do apologise if the answer is trivial or documented elsewhere. I did my best to research about it and didnt find what I was lookign for.
Best regards,
George
Accepted Answer
More Answers (0)
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!