Generating a random binary matrix
87 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
imed NASRI
am 6 Jan. 2014
Kommentiert: Jack Nelson
am 13 Mai 2020
Hello,
I want to generate randomly a (nxm) matrix of binary variables (0 and 1) in matlab. Is there someone who has a suggestion? Thanks.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Jos (10584)
am 6 Jan. 2014
Some other suggestions
n = 4 ; m = 5 ;
A1 = rand(n,m) < 0.5 % a logical array consuming little memory
A2 = round(rand(n,m))
N0 = ceil(n*m/3) ; % specify some exact number of zeros
A3 = ones(n,m) ; A3(1:N0) = 0 ; A3(randperm(numel(A3))) = A3
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!