How can I determine the relative frequency of a value in a MATLAB vector?
vector = [ 2 2 2 2 1 1 1 2 2 1 1 1 2 2 2 2 1 2 ];
What function will return the number of occurrences of each unique element?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
uniquein combination withhistcto get the relative frequency.This gives the unique elements as
unqA=[1,2,3,4]. To get the number of occurances,This gives
countElA=[3,3,1,1]andrelFreq=[0.3750, 0.3750, 0.1250, 0.1250], which is the relative frequency of the unique elements. This will work for both integers and floating points.