MATLAB: Count how many elements are present inside arrays

elementsfindhistogramMATLABrepeated

Given the following vector
V= [1 2 3 4 7 8 9 10 11 12 14 16 17];
and the vectors
P = [1 2 3 4 7 8 9 10 11 12 14 16 17 2 7 9 11 12 3 1 10];
F = [1 2 3 4 7 9 10 11 12 14 16 17 3 7 9 11 14 16 1];
I want to create two new vectors A and B that count how many times the element in V are present in P and F.
A= [2 2 2 1 2 1 2 2 2 2 1 1 1 ]. % Refer to P
Element 1 is present 2 times in P. Element 2 is present 2 times in P…. Element 8 is present 1 time in P. Element 9 is present 2 times in P …
B= [2 1 2 1 2 0 2 1 2 1 2 2 1]. %Refer to F
Element 1 is present 2 times in F. Element 2 is present 1 times in F…. Element 8 is present 0 time in F. Element 9 is present 2 times in F …

Best Answer

>> A = hist(P,V)
A =
2 2 2 1 2 1 2 2 2 2 1 1 1
>> B = hist(F,V)
B =
2 1 2 1 2 0 2 1 2 1 2 2 1