How can i randomly insert 14 1's in a array of two thousand zeros?

2 visualizzazioni (ultimi 30 giorni)
i.e. I have a array of two thousand zeros, in this I want to randomly insert 1, fourteen times. How can I do this?

Risposta accettata

John D'Errico
John D'Errico il 7 Ago 2020
A = zeros(1,2000);
A(randperm(2000,14)) = 1;

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