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

조회 수: 7 (최근 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