How to count number of times 2 elements appear together in a table

2 ビュー (過去 30 日間)
Michael Boyle
Michael Boyle 2021 年 4 月 30 日
編集済み: Scott MacKenzie 2021 年 4 月 30 日
I have a table of teams and names and I want to get an output of the number of times 2 specific names appear together in the table. For example, I want to know the number of times that 'person2' and 'person4' appear in the same row in columns 2 and 3 and in columns 5 and 6. The name placements are randomized every time the code is run so it would need to work for every new table

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 4 月 30 日
編集済み: Scott MacKenzie 2021 年 4 月 30 日
p1 = 'person5'; % as an example
p2 = 'person4'; % as an example
sum(strcmp(T{:,2},p1) & strcmp(T{:,3},p2) & ...
strcmp(T{:,5},p1) & strcmp(T{:,6},p2));

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by