Select specific number of random ones placed in a zeros matrix

1 vue (au cours des 30 derniers jours)
Chiagoziem Ngwadom
Chiagoziem Ngwadom le 17 Oct 2019
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?

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by