ある2サンプル間にお​いて各時点で結果が一​致するか否かの配列を​作成

2 views (last 30 days)
Manori
Manori on 8 Feb 2023
Commented: Manori on 9 Feb 2023
例えば、3サンプル*3時点のテーブルデータがあるとして、ある2つのサンプル間において結果が各時点で一致するか否かを示す配列を作りたいと考えています。
例)
既存データ
Time: 1 1 1 2 2 2 3 3 3
Sample: a b c a b c a b c
Result: A A B C A B A C C
作成したいデータ
a-b: 1 0 0
b-c: 0 0 1
c-a: 0 0 0
3サンプルなら力技でなんとかなりそうなのですが、実際には20サンプル*40000ポイントのデータについて全組合せ(190通り)で一致しているか否かの配列を作りたいので、効率的に最終データを取得するにはどうしたら良いでしょうか?

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 8 Feb 2023
Edited: Atsushi Ueno on 8 Feb 2023
20サンプル*40000ポイントのデータは下記の様に40000行20列のデータとして表せます。比較対象は全組み合わせである点を見落としていたので回答を変更しました。
% | a b c
% ----------
% 1 | A A B
% 2 | C A B
% 3 | A C C
data = randi(3,40000,20); % 20サンプル*40000ポイントのサンプルデータ
indx = nchoosek(1:size(data,2),2); % 比較する列の組み合わせ
cmp1 = data(:,indx(:,1)); % 比較データその1
cmp2 = data(:,indx(:,2)); % 比較データその2
result = cmp1 == cmp2; % 元データと循環シフトしたデータを比較
size(result) % 結果は190比較分*40000ポイントの行列になる(1:一致、0:不一致)
ans = 1×2
40000 190
  1 Comment
Manori
Manori on 9 Feb 2023
まさに求めていたものです!
ご回答いただきありがとうございました!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!