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

2 次查看(过去 30 天)
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?

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by