One vector split into zeros and ones

5 visualizzazioni (ultimi 30 giorni)
Sue MM
Sue MM il 10 Lug 2018
Risposto: OCDER il 10 Lug 2018
Hello, I am trying to create a simple array with half of it being zeros half of it being 1s what is the simple way of doing it? The length of it is based on a certain length of another variable so I create a variable that would store the length. The expected array that I want is [000000000.....11111111]
Thanks!

Risposta accettata

OCDER
OCDER il 10 Lug 2018
Alternatively, you could use repelem that'll be ~2x faster
x = repelem([0 1], n/2)

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by