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!