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

2 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

John D'Errico
John D'Errico le 7 Août 2020
A = zeros(1,2000);
A(randperm(2000,14)) = 1;

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