How do I create a vector of n consecutive numbers spaced at with an interval of m between each group, without using a for loop?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Seb Long
el 18 de Jun. de 2018
Comentada: Seb Long
el 18 de Jun. de 2018
Is it possible to generate the following vector:
v=[1,2,3 ,6,7,8 ,11,12,13 ....]
without using a for loop? More generally, I would like to be able to generate groups of n consecutive numbers with an interval of m between each group (in the example n=3 and m=2).
Thank you in advance..
0 comentarios
Respuesta aceptada
Más respuestas (1)
Honglei Chen
el 18 de Jun. de 2018
Editada: Honglei Chen
el 18 de Jun. de 2018
Here is one possible solution
N = 9;
n = 3;
m = 2;
x = buffer(1:N,n);
x = x+(0:size(x,2)-1)*m;
x(1:N).'
HTH
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!