|
"Alex " <alaios@yahoo.com> wrote in message <jh0ti1$hvp$1@newscl01ah.mathworks.com>...
> Dear all,
> I would like to create in matlab a point sampling matrix of [m,n] dimension.
>
>
> Such a matrix has m rows and n columns
> -it has all the elements zeros but each row has one element "1" random
> but
> -each column can only have one "1" element
>
> Is it possible in matlab to do something like that in a smart way? Of course one can build it with loops of for and while but this is gonna take ages to finish when the matrix size increases
>
> Regards
> Alex
- - - - - - - - -
With m rows each containing 1 one that would make a total of m ones altogether. With n columns each containing 1 one it would be a total of n ones. Therefore your request is impossible unless m and n are equal.
With m equal to n, do this:
x = zeros(n);
x(randperm(n)+n*(0:n-1)) = 1;
Roger Stafford
|