One vector split into zeros and ones

4 ビュー (過去 30 日間)
Sue MM
Sue MM 2018 年 7 月 10 日
回答済み: OCDER 2018 年 7 月 10 日
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!

採用された回答

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by