creating binary vector with determed number of ones

1 次查看(过去 30 天)
Hello,
i have a vector V= 50; i want to full this vector randomly with 0 and 1. the '1' appears 10 times and the rest of the vector with zeros. how can i do that please

采纳的回答

John D'Errico
John D'Errico 2019-4-24
编辑:John D'Errico 2019-4-24
nones = 10;
nv = 50;
V = zeros(1,nv);
V(randperm(nv,nones)) = 1;
  3 个评论
John D'Errico
John D'Errico 2019-4-24
I'm sorry. I cannot/will not keep on chasing totally new questions in the comments. That turns one question into an extended personal consulting session. If you have another question, then ask it. AS ANOTHER QUESTION.
loukil sana
loukil sana 2019-4-24
ok no problem thank you. i will post it as a new question

请先登录,再进行评论。

更多回答(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