Run length encoding of vectors in MATLAB: looped version and vectorized version
I'm not sure about the performance of my following code however I'm using tabulate() to do the job. As you can see, the loops for filtering elements not to compute the frequency of elements. In other words, you might want to look at tabulate() or hist() to compute the frequent occurrence of elements. 

x = [20 13 12 12 12 18 17 16 16 11];
j = 1;
elems = []; % store repeated elements
for i = 1:length(x)
    if isempty(find(elems == x(i)))
        elems(j) = x(i);
        j = j + 1;
    end
end
elems
t = tabulate(x); % get frequency table
for i = 1:length(elems)
    lens(i) = t(elems(i),2); % get how many each element in elems vector occurs
end
lens


The result is

elems =
    20    13    12    18    17    16    11
lens =
     1     1     3     1     1     2     1