ある2サンプル間において各時点で結果が一致するか否かの配列を作成
2 views (last 30 days)
Show older comments
例えば、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通り)で一致しているか否かの配列を作りたいので、効率的に最終データを取得するにはどうしたら良いでしょうか?
0 Comments
Accepted Answer
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:不一致)
More Answers (0)
See Also
Categories
Find more on Transmitters and Receivers 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!