MATLAB: How to get an index like with ismember, but with values representing the number of occurances

index wordsismemberMATLABstrcmp

I have some vectors, let's call them A and B, and I want to find all elements of A contained within B. So far I've gotten an logical index of all the unique elements, but I need to go one step further and count up repetitions as well. So for instance:
A = ['monday', 'tuesday', 'thursday', 'monday']
B = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
Index = [2 1 0 1 0 0 0]

Best Answer

>> A = {'monday', 'tuesday', 'thursday', 'monday'};
>> B = {'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'};
>> idx = cellfun(@(s)nnz(strcmp(A,s)),B)
idx =
2 1 0 1 0 0 0