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

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 14 de Ag. de 2020
m=2;
N=100;
a=zeros(1,N);
a(m+1:m+1:N)=1

Más respuestas (2)

Sean de Wolski
Sean de Wolski el 14 de Ag. de 2020
repmat([zeros(1,m), 1],1,5)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 14 de Ag. de 2020
Hi,
O=zeros(1, 20);
m=input('m = ');
IN=m+1:m+1:numel(O);
O(IN)=1;

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by