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

1 次查看(过去 30 天)
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)

Sulaymon Eshkabilov
Hi,
O=zeros(1, 20);
m=input('m = ');
IN=m+1:m+1:numel(O);
O(IN)=1;

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by