How to calculate number of times a pair appear in an array

4 ビュー (過去 30 日間)
Ray
Ray 2015 年 9 月 4 日
回答済み: Ray 2015 年 9 月 4 日
Let's say I have an array as such:
X and Y is the original data, and I hope to find Z, which is the number of times the pair X&Y occurs in the array.
eg. X=1 & Y=2 occurs 2 times X=1 & Y=3 occurs 2 times X=2 & Y=1 occurs 3 times X=2 & Y=2 occurs 1 times
This is just a simple example, my real data is in random order, but the idea is the same, how to get the number of times both elements X&Y pair occurs and save in in XYZ array?

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 9 月 4 日
data=[1 2;4 5;1 2;7 8;1 2;4 5]
[ii,jj,kk]=unique(data,'rows')
out=[ii histc(kk,1:size(ii,1))]

その他の回答 (1 件)

Ray
Ray 2015 年 9 月 4 日
Thank you for the very quick reply. You've made my life so much easier. Thank you again!!

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by