How to generate all binary matrix by permuting subdiagonal elements in Matlab -
i interested in considering changes the sub-diagonal entries let diagonal , upper-triangular entries zero. closed formula total number of permutations given 2^( n choose 2 ). n=4 case have
d_1 x(2,1) d_2 x= x(3,1) x(3,2) d_3 x(4,1) x(4,2) x(4,3) d_4
where upper triangular entries , d_i's equal zero.
i know there 64 different matrices, how generate them n?
first, figure out how extract/emplace subdiagonal elements. how just:
sub_idx = find(~triu(ones(n)));
now use vector of indices permanent mapping of binary values subdiagonal. now, need matrix of possible binary values:
num_combs = 2^length(sub_idx); binary_combs = dec2bin(0:num_combs-1).' - '0';
and k'th combination matrix is:
mtx = zeros(n); mtx(sub_idx) = binary_combs(:,k);
(editing add single output matrix option)
if want them in 1 big 3d matrix, instead:
tmp = zeros(n*n, num_combs); tmp(sub_idx, :) = binary_combs; mtx = reshape(tmp, [n n num_combs]);
Comments
Post a Comment