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

2 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

John D'Errico
John D'Errico el 7 de Ag. de 2020
A = zeros(1,2000);
A(randperm(2000,14)) = 1;

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by