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

1 view (last 30 days)
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?

Accepted Answer

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

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!