フィルターのクリア

how to generate a vector of zeros with 2 random successives cell containing ones

2 ビュー (過去 30 日間)
loukil sana
loukil sana 2019 年 4 月 24 日
回答済み: Rik 2019 年 4 月 24 日
how to generate a vector of zeros with 2 random successives cell containing ones
  1 件のコメント
Adam Danz
Adam Danz 2019 年 4 月 24 日
What does "2 random successives cell" mean?
Vector of zeros
zeros(1,15)
Vector of ones
ones(0,15)

サインインしてコメントする。

回答 (2 件)

Star Strider
Star Strider 2019 年 4 月 24 日
I have no idea what you want.
Try this:
z = zeros(1, 20); % Vector Of 20 Zeros
idx = randi(numel(z)-1); % Choose An Index
z(idx:idx+1) = 1; % Define Consecutive Indices = 1

Rik
Rik 2019 年 4 月 24 日
If you don't mean cell, but element:
n=10;%vector length
v=zeros(1,n);
one_ind=randi(n-1,1);
v(one_ind+[0 1])=1;
If you do want a cell array:
n=10;%vector length
v=zeros(1,n);
one_ind=randi(n-1,1);
v(one_ind+[0 1])=1;
v=num2cell(v);

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by