MATLAB: Sum of number of pairs

2 columnscount timesdesintationorigin

I have two columns x and y. Each contains only 8 values. These are numerical but are descriptive (nominal). I want to get an 8×8 matrix with the count of how many times a particular set happened.
For background info x and y are origins and destinations. Each row is a shipment and I need to know how many shipments between the origin and destination.
Small example (2×2):
x = a a a a b b b b b b
y = a a a b b b b a a a
M = [3 2;3 2]

Best Answer

[~,~,xtags] = unique(x);
[~,~,ytags] = unique(y);
accumarray([xtags(:),ytags(:)],1)
ans =
3 1
3 3
I think you miscounted those combinations for your example.