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

2 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

John D'Errico
John D'Errico am 7 Aug. 2020
A = zeros(1,2000);
A(randperm(2000,14)) = 1;

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by