count bins

Hello, i need help in counting bins. I have this command in mathematica:
nBin = BinCounts[dataX, {-5 sX, 5 sX, step}]
,where datax is a matrix. How can i possible write it in matlab?

 Accepted Answer

Matt Fig
Matt Fig on 12 Feb 2011

0 votes

I think you might need to use the HISTC function. Have a look at the help to see if it meets your needs.

7 Comments

George
George on 12 Feb 2011
I 've looked it but the problem is that i must find the bin counts.In histc you must supply the number of bins if i understood it well.
Walter Roberson
Walter Roberson on 12 Feb 2011
It appears the equivalent would be
histc(dataX(:), -5*sX:step:5*sX)
but watch out for the boundary conditions.
Walter Roberson
Walter Roberson on 12 Feb 2011
No, in histc() you supply the bin boundaries. It is hist() that you can supply bin counts.
Matt Tearle
Matt Tearle on 13 Feb 2011
Both HIST and HISTC will return bin counts, for a given vector of bin divisions. The difference is whether you specify the bin edges or centers.
Walter Roberson
Walter Roberson on 13 Feb 2011
Yes, but hist() allows you to specify just the number of bins; hist(X) uses nbins = 10, hist(X,nbins) with nbins a scalar uses that number, hist(X,y) with y a vector uses the given y values as the centers of bins. The algorithm for determining the boundaries of the bins given the number of them is not described in the hist() documentation.
histc() has no mode in which one can give the number of bins: it can only be used in the mode where one specifies the edges of bins. histc(x,y) with y a scalar would count the number of values in x that are exactly equal to the scalar y, as in sum(x==y) .
George
George on 13 Feb 2011
The histc(datax(:), -5*sX:step:5*sX) worked just fine!Thank you!
Matt Tearle
Matt Tearle on 13 Feb 2011
@WR: sorry, I missed George's first comment, so I missed the context of the discussion. Another thing to add to wish list, I think...

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Asked:

on 12 Feb 2011

Community Treasure Hunt

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

Start Hunting!