arrays - Incremental issue with creating histogram (JavaScript) -


using code below trying create histograms of values in each row of dist, each row of hist histogram of 10 bins. step floating point value (0.12158...).

 for(i = 0; < dist.length; i++){     for(j = 0; j < dist[0].length; j++){         bin = parseint(dist[i][j]/step);         if(bin == 10)             bin = 9;         hist[i][bin]+=1;     } } 

dist 2d array declared as:

var dist = []; for(var x = 0; x < 77; x++){     dist[x] = [];         for(var y = 0; y < 50; y++){          dist[x][y] = x*y;         }     } 

hist declared as:

var hist = []; for(var x = 0; x < 77; x++){     hist[x] = [];         for(var y = 0; y < 10; y++){          hist[x][y] = x*y;         }     } 

the first row of hist gives me results expect, frequencies totalling 50. however, values in bins of next rows not start zero, values of these sum of values previous histograms plus current value.

for example, first row of hist:

[1, 10, 8, 9, 6, 7, 4, 3, 1, 1] 

the second row of hist:

[1, 10, 10, 13, 10, 12, 10, 9, 10, 10] 

any appreciated!


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -