MATLAB: Create a binary sequence that consisting of m zeros and n ones in any order.

binary sequence

I need help to program a matlab code to generate a binary sequence that contains m zeros and n ones. I created a N lengths of zero, x1=zeros(1,N), but how to add n ones into the sequence of zeros.

Best Answer

The easiest way:
x1 = [zeros(1,N) ones(1,M)];