From: ltaboada T. Antelo on
Hi all:

I want to create a matrix of a given dimension MxN composed by zeros and ones with the following characteristics:

1. For each row i only a 1 located in a random column j must exist (all other position (i,j) must be zero)
2. The sum of all row i for a given column j must be equal to 1 (i.e only a position with 1 must exist in each column).
2. The sum of all column j for a given column i must be equal to 1 (i.e only a position with 1 must exist in each row).

An example of I want can be the following 5x5 matrix:

0 0 0 1 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 0 1

or

1 0 0 0 0
0 0 1 0 0
0 0 0 0 1
0 0 0 1 0
0 1 0 0 0

Waiting for your help.

Thank you in advance

Luis
From: us on
"ltaboada T. Antelo" <luistabo(a)yahoo.es> wrote in message <hv7bgv$bqr$1(a)fred.mathworks.com>...
> Hi all:
>
> I want to create a matrix of a given dimension MxN composed by zeros and ones with the following characteristics:
>
> 1. For each row i only a 1 located in a random column j must exist (all other position (i,j) must be zero)
> 2. The sum of all row i for a given column j must be equal to 1 (i.e only a position with 1 must exist in each column).
> 2. The sum of all column j for a given column i must be equal to 1 (i.e only a position with 1 must exist in each row).
>
> An example of I want can be the following 5x5 matrix:
>
> 0 0 0 1 0
> 1 0 0 0 0
> 0 1 0 0 0
> 0 0 1 0 0
> 0 0 0 0 1
>
> or
>
> 1 0 0 0 0
> 0 0 1 0 0
> 0 0 0 0 1
> 0 0 0 1 0
> 0 1 0 0 0
>
> Waiting for your help.
>
> Thank you in advance
>
> Luis

one of the many solutions

n=5; % <- size of your mat...
m=eye(n);
rix=randperm(n);
m=m(rix,:);

us