Two questions about "hist" function

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);






Result:



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?





Comments

  • 1. In this case you can find the mean value of xout:

    sep=mean(xout);

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

    pos_group1=find(asep);

    Find the values of the elements:
    group1=a(pos_group1);
    group2=a(pos_group2);

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

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

Howdy, Stranger!

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

Categories

In this Discussion