Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.