I want to get better at vectorizing my loops in MATLAB. At the moment, I'm trying to count the occurrences of values in a list of ints. My code is similar to this:
list = [1 2 2 3 1 3 2 2 2 1 5];
occurrence_list = zeros(1,max(list));
for x=list
occurrence_list(x) = occurrence_list(x) + 1;
end
Is there a simple vectorized replacement for that for loop? (Or is there a built in MATLAB function that I'm missing?) I'm doing this on pretty small data sets, so time isn't an issue. I just want to improve my MATLAB coding style. Thanks for any suggestions!