## counting total no of particles in a bin in histogram

### Sumera Yamin (view profile)

on 23 Aug 2019
Latest activity Commented on by dpb

on 23 Aug 2019

### Saurabh Kelkar (view profile)

Hi, i have a basic problem. I had made a histogram with nbins = 100.
I want to count the number of particles of that which is maximum number of particles and display it.
what should be the best way to do it.
Thank you very much. Any help is highly appreciated.

dpb

### dpb (view profile)

on 23 Aug 2019
Which one of the veritable multitude of binning functions now available did you use, specifically? Show us code you used.
Ted Shultz

### Ted Shultz (view profile)

on 23 Aug 2019
Did you try looking at the counts property of the histogram object?
Sumera Yamin

### Sumera Yamin (view profile)

on 23 Aug 2019
x = randn (100,1);
n = 100;
hist (x, n);
minz = min (x);
maxz = max (x);
n_bin = (maxz-minz) / n;
% i want to locate the bin with highest number of counts and then divide total sum of that bin with n_bin.

### Saurabh Kelkar (view profile)

on 23 Aug 2019

k = hist(x,n);
gives the counts in each of the bins.
modalBin = find(k==max(k) % Gets the bin number of highest bin. Will return two bins if clashes
Alternatively i would recommend using ecdf funtion for doing this.

dpb

### dpb (view profile)

on 23 Aug 2019
Which illustrates also a conundrum -- two functions of nominally same purpose and two different results...so which one is "right"?
All depends on the binning algorithm that TMW changed between the two.
Ted Shultz

### Ted Shultz (view profile)

on 23 Aug 2019
It looks like hist is discouraged by mathworks...
dpb

### dpb (view profile)

on 23 Aug 2019
Indeed, but there are some real advantages with them with respect to the new versions...the binning difference above being one and the ease in setting bins for certain specific uses. "Not everything new is necessarily improved."