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
0 件のコメント
採用された回答
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
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!