How to sort multiple arrays into bins generated by another array?

12 次查看(过去 30 天)
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

采纳的回答

the cyclist
the cyclist 2021-8-9
编辑:the cyclist 2021-8-9
If you use the 3rd output of the histcounts function on your data, I believe you'll get the indexing you want, and your other tasks follow from that..
  1 个评论
George Kokkinos
George Kokkinos 2021-8-9
编辑:George Kokkinos 2021-8-9
Thank you for your response. I will check it out and mark your answer accordingly.
You are right! I didnt realise that there was a third output. I believe I work out everything else.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by