Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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






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

  • giuggiug Posts: 217Member
    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"
  • rnayebirnayebi Posts: 4Member
    Very Thanks
Sign In or Register to comment.