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
You can use the function tabulate. See this example with your vector.
vector = [ 2 2 2 2 1 1 1 2 2 1 1 1 2 2 2 2 1 2 ]; tabulate(vector); Value Count Percent 1 7 38.89% 2 11 61.11%
If you need it in percent order, do:
t = tabulate(vector); t = sortrows(t, 3)