create a binary sequence that consisting of m zeros and n ones in any order.
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(3 个)
Roger Stafford
2014-11-23
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 个评论
Azzi Abdelmalek
2014-11-23
编辑:Azzi Abdelmalek
2014-11-23
x1=[zeros(1,5) ones(1,4)]
%or
N=5;
n=4;
X1=1:n+N>N
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!