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 w
For the most general case where you have a vector of floating point values, you can use the functions UNIQUE and ACCUMARRAY:
[uniqueValues,~,uniqueIndex] = unique(vector); frequency = accumarray(uniqueIndex(:),1)./numel(vector);