Column-wise AND operation in all column combinations of two matrices
10 ビュー (過去 30 日間)
古いコメントを表示
Giorgos Papakonstantinou
2014 年 2 月 24 日
回答済み: Giorgos Papakonstantinou
2014 年 2 月 24 日
Given matrix a of size MxN and matrix b of size MxL I want to get a matrix C of size M x(N*L) which contains the column-wise logical operation AND of all combinations of columns of matrix a and matrix b.
a = [1 0 0
1 0 0
1 0 0
1 0 0
0 1 0
0 1 0
0 1 0
0 1 0
0 0 1
0 0 1
0 0 1
0 0 1];
b= [0 0 1
0 1 0
1 0 0
0 0 1
0 1 0
1 0 0
0 0 1
0 1 0
1 0 0
0 0 1
0 1 0
1 0 0];
C=[];
for ii=1:size(a, 2)
for jj=1:size(b, 2)
C = [C b(:,jj) & a(:,ii)];
end
end
I am searching for an alternative syntax of the above loops. Thank you!
1 件のコメント
Jos (10584)
2014 年 2 月 24 日
A matrix of size MxN, means M rows and N columns, rather than the other way around ...
採用された回答
Iain
2014 年 2 月 24 日
This should do it:
C = bsxfun(@and, a, reshape(b,[12,1,3]);
theresult = C(down,column_a,column_b);
0 件のコメント
その他の回答 (3 件)
Azzi Abdelmalek
2014 年 2 月 24 日
out=reshape(repmat(a,size(b,2),1),size(a,1),[]) & repmat(b,1,size(a,2))
0 件のコメント
Jos (10584)
2014 年 2 月 24 日
% Small example: two logical arrays
A = rand(3,3) > .25
B = rand(2,3) > .25
% general engine
[ib,ia] = ndgrid(1:size(B,1), 1:size(A,1))
C = A(ia(:),:) & B(ib(:),:)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Descriptive Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!