Most common pair in a matrix.
1 view (last 30 days)
Show older comments
I have a list of lat/lon coordinates and I would like to find the most common locations. Is there a built in function for this?
Thank you.
0 Comments
Accepted Answer
Star Strider
on 4 Nov 2020
Try this:
M = randi(5, 25, 2); % Create ‘LatLon’ Data
[Mu,~,idx] = unique(M, 'rows'); % Unique Rows
Tally = accumarray(idx, (1:numel(idx)).', [], @(x) {M(x,:)}); % Calculate Frequencies, Return Pairs By Group
pairs = cellfun(@(x)size(x,1), Tally); % Recover ‘LatLon’ Pairs
[~,ixs] = sort(pairs, 'descend'); % Sort Them
Result = table(Mu(ixs,:),pairs(ixs), 'VariableNames',{'LatLon','Frequency'}); % Output Table Of Pairs & Frequencies
2 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!