MATLAB: Count number of elements in a matrix

occurenceprobability

I have an array A = [1 2 3 4 5 6 7 8 9 10]
And I want to calculate number of times the elements of A repeat in any matrix subset of A e.g. if B = [ 2 5 5] then answer should be C = [0 1 0 0 2 0 0 0 0 0]

Best Answer

"Count number of elements in a matrix"
That is exactly what histograms are:
>> A = [1 2 3 4 5 6 7 8 9 10];
>> B = [2,5,5];
>> histc(B,A)
ans =
0 1 0 0 2 0 0 0 0 0