MATLAB: Column-wise AND operation in all column combinations of two matrices

logical?

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!

Best Answer

This should do it:
C = bsxfun(@and, a, reshape(b,[12,1,3]);
theresult = C(down,column_a,column_b);