MATLAB: How can i randomly insert 14 1’s in a array of two thousand zeros

arrayrandomrandom number generator

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?

Best Answer

A = zeros(1,2000);
A(randperm(2000,14)) = 1;