Select specific number of random ones placed in a zeros matrix

1 visualizzazione (ultimi 30 giorni)
Hi guys, I am trying to make a 1024 by 1024 zeros matrix with specifically 20 ones randomly placed anywhere within the zeros matrix. I feel like it's easy but can anyone help?

Risposta accettata

Guillaume
Guillaume il 17 Ott 2019
m = zeros(1024, 1024);
m(randperm(numel(m), 20)) = 1; %place 20 ones randomly in m.

Più risposte (0)

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