Sum of number of pairs?
6 views (last 30 days)
Show older comments
I have two columns x and y. Each contains only 8 values. These are numerical but are descriptive (nominal). I want to get an 8x8 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 (2x2):
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]
1 Comment
Azzi Abdelmalek
on 4 May 2016
What are your data and what is the result? How did you get the result?
Accepted Answer
John D'Errico
on 4 May 2016
[~,~,xtags] = unique(x);
[~,~,ytags] = unique(y);
accumarray([xtags(:),ytags(:)],1)
ans =
3 1
3 3
I think you miscounted those combinations for your example.
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!