Paulo
Posts:
339
Registered:
5/28/10
|
|
Re: Symmetrical binary matrices: a help from an expert
Posted:
Jan 27, 2011 8:10 PM
|
|
Just a few corrections
a=[]; %clear the output matrix n=5; %number of rows n1=randi([1 n-1]); %ones per rows o=ones(1,n1); %vector with the ones z=zeros(1,n-n1); %vector with the zeros p=perms([o z]); %join ones and zeros in the same vector and permute them for x=1:n b=p(p(:,x)==0,:);%find the permuted lines with zero at the diagonal bx=randi([1 numel(b(:,1))]); %select a random rows of b a(x,:)=b(bx,:); %save the random rows to the output end p=[]; %clear some memory, specially useful when n is big (lots of permutations) a %Random matrix with the same number of ones per rows and diag=0
|
|