random vectorof zeros and 1

조회 수: 2 (최근 30일)
joseph Frank
joseph Frank 2013년 4월 20일
Hi,
if I want to generate a random vector of length 1000 where 700 are zeros and 300 are ones how can I do so? I want the zeros and ones to be have a random occurrence in the vector. for example:
A=[ 1 0 1 1 0 1 0 0 .....1] % till observation 1000;
Thanks

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 4월 20일
A=zeros(1,1000)
A(randperm(1000,300))=1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by