Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Symmetrical binary matrices: a help from an expert
Replies: 15   Last Post: Jan 29, 2011 3:13 AM

 Messages: [ Previous | Next ]
 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

Date Subject Author
1/27/11 Paulo Guimaraes
1/27/11 Bruno Luong
1/27/11 Bruno Luong
1/27/11 Paulo
1/27/11 Paulo
1/28/11 Bruno Luong
1/28/11 Paulo
1/28/11 Bruno Luong
1/28/11 Paulo
1/28/11 Bruno Luong
1/28/11 Bruno Luong
1/28/11 Bruno Luong
1/28/11 Bruno Luong
1/28/11 Paulo
1/28/11 Paulo
1/29/11 Bruno Luong