Two questions about "hist" function - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Two questions about "hist" function

rnayebirnayebi Posts: 4Member
I have two questions about "hist". As you know, [n,xout] = hist(...) returns vectors n and xout containing the frequency counts and the bin locations.

a = [7 3 8 4 2 6 9 4 3];

[n,x] = hist(a,2);


n =

5 4

x =

3.7500 7.2500

1. How can I obtain the elements (or indexes of elements) which exist in the first interval or second interval? For instance, at the above example for first interval the elements {2,3,3,4,4} and for second interval the elements {6,7,8,9}.

2. How can I use the hist function when I have a Three dimensional vector (a matrix(3*3)) instead of a single dimensional vector?


  • giuggiug Posts: 217Member
    1. In this case you can find the mean value of xout:


    use the function find to have the positions of the elements of the two groups:


    Find the values of the elements:

    2. for matrixes you can use the hist function in this way:
    b=[1 1 1 ; 2 1 1; 3 2 1];

    b(:) signify "consider all the elements of b"
  • rnayebirnayebi Posts: 4Member
    Very Thanks
Sign In or Register to comment.