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?
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(1 个)
Honglei Chen
2018-6-18
编辑:Honglei Chen
2018-6-18
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!