One vector split into zeros and ones

조회 수: 5 (최근 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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by