The following procedure might help you, where X is the second column of the matrix which needs to be binned:
bins = [start_position of x (in mm): 10: end_position of x (in mm)+1]
Y = discretize(X,bins) will give which value belongs to which bin
To get number of values in a bin following can be used:
[Y,E] = discretize(X,bins,diff(bins))
Where Y will give each bin’s count and E will give the bins
The above procedure can be followed for uniform bins but for non-uniform bins, it can defined as -
bins = [start_position of x (in mm), start_position of x (in mm) + 5 (in mm) :10: end_position of x (in mm) - 4(in mm) , end_position of x (in mm)+1] .