create a vector of 0 and 1s that takes 1 at a fixed interval

1 回表示 (過去 30 日間)
alpedhuez
alpedhuez 2020 年 8 月 14 日
回答済み: Sulaymon Eshkabilov 2020 年 8 月 14 日
I would like to create a vector of 0s that takes 1 at a given (m) interval. For example, if m=2, the vector will be like
0,0,1,0,0,1,0,0,1,...
what will be a simpler way to create such vector?

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 8 月 14 日
m=2;
N=100;
a=zeros(1,N);
a(m+1:m+1:N)=1

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2020 年 8 月 14 日
repmat([zeros(1,m), 1],1,5)
  1 件のコメント
alpedhuez
alpedhuez 2020 年 8 月 14 日
編集済み: alpedhuez 2020 年 8 月 14 日
Thank you.

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


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 8 月 14 日
Hi,
O=zeros(1, 20);
m=input('m = ');
IN=m+1:m+1:numel(O);
O(IN)=1;

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by