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

6 visualizaciones (últimos 30 días)
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

Respuesta aceptada

the cyclist
the cyclist el 9 de Ag. de 2021
Editada: the cyclist el 9 de Ag. de 2021
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 comentario
George Kokkinos
George Kokkinos el 9 de Ag. de 2021
Editada: George Kokkinos el 9 de Ag. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by