create a binary sequence that consisting of m zeros and n ones in any order.
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
Più risposte (3)
Roger Stafford
il 23 Nov 2014
Or perhaps you want them in random order:
x = zeros(1,m+n);
p = randperm(1:m+n,n);
x(p) = ones(1,n);
4 Commenti
Azzi Abdelmalek
il 23 Nov 2014
Modificato: Azzi Abdelmalek
il 23 Nov 2014
x1=[zeros(1,5) ones(1,4)]
%or
N=5;
n=4;
X1=1:n+N>N
4 Commenti
Vedere anche
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!