Repetitive sequence with calculations
1 view (last 30 days)
Show older comments
Hello all,
I am trying to create the following sequence of numbers:
5 6 7 5 6 7 5 6 7 8 9 10 8 9 10 8 9 10 11 12 13 ...
To be more specific, 5 6 7 will be repeated three times and then +1 to each element and repeat another three times. The amount of iterations would be pre-defined f.e. n times.
This is what I tried but it didn't work:
a=[5 6 7]
x = []
n=9
for i=1:n
s=3+a
for j=1:3
m(i,j)=s(i)
end
b=s+3
x = [x,b];
end
Huge thanks in advance!
0 Comments
Accepted Answer
David Hill
on 12 Feb 2020
a=[5 6 7];
x=zeros(1,9*n);
for j=1:n
x(9*(j-1)+1:9*j)=repmat(a,1,3);
a=a+3;
end
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!