random vectorof zeros and 1

1 vue (au cours des 30 derniers jours)
joseph Frank
joseph Frank le 20 Avr 2013
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

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 20 Avr 2013
A=zeros(1,1000)
A(randperm(1000,300))=1

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by