how to do binning from two array?

i have two array. one array contained floating values. DT = {2.23, 2.83, 3.00, 3.16, 3.60, 4.00, 4.12, 4.24, 4.47, 5.00, 5.09, 5.38, 5.83, 6.00}. Second array contains occurrence of these float values . Freq = {18, 83, 517, 195, 110, 89, 6, 3, 10, 15, 4, 3, 2, 1}. means 2.23 value occurred 18 times like this. Now, i want to do binning from these two array. i want to divide it in 50 bins. each bin groups like [0-2], [2-4], [4-6].... like this. and i have to get the summation of the occurrence of the float values fall in this range. means 2.23, 2.83,3.00, 3.16, 3.60, 4.00 these are fall in the range [2-4] so i need to sum its corresponding occurrence values and put it in a array. how to do it?? please give a suggestion

Réponses (1)

Jos (10584)
Jos (10584) le 12 Déc 2017

0 votes

Here is an easy solution:
DT = [2.23, 2.83, 3.00, 3.16, 3.60, 4.00, 4.12, 4.24, 4.47, 5.00, 5.09, 5.38, 5.83, 6.00]
Freq = [18, 83, 517, 195, 110, 89, 6, 3, 10, 15, 4, 3, 2, 1]
Bins = 0:2:10
[~, idx] = histc(DT, Bins)
MySums = accumarray(idx(:), Freq(:),[numel(Bins)-1 1])

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by