How do I create random Boolean array with at least one 1 in each row?

10 visualizzazioni (ultimi 30 giorni)
How do I create random Boolean array with at least one 1 in each row?

Risposte (1)

James Tursa
James Tursa il 31 Mar 2015
Modificato: James Tursa il 31 Mar 2015
For a row, e.g.,
n = number of random numbers in a row
row = randi(2,1,n)-1;
while( ~any(row) )
row = randi(2,1,n)-1;
end

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by