I've a large D Matrix of size MxNxK. Given a binary mask B of size MxN, I would like to split the matrix D into two submatrices: D0 and D1, in such a way that matrix D0 has the values of matrix D associated with the 0's in the binary mask. The same is valid for D1, but by using the 1's in the binary mask.
Currently, I'm solving this issue by using loops, but I'm wondering if there's a more efficient way to solve that?
mat_zeros = [];
mat_ones = [];
for m=1:M
for n=1:N
matval = matrixbig(m,n,:);
matval = matval(:)'; % mapping matval to a K-dimensional vector
if (binmask(m,n) == 1)
mat_ones = [mat_ones; matval];
elseif (binmask(m,n) == 0)
mat_zeros = [mat_zeros; matval];
end
end
end
All suggestions are welcomed ;-)