Replicating a vector while summing an increasing value
3 次查看(过去 30 天)
显示 更早的评论
I have this vector: a = [ 7 8 9 7 8 9]; and I would like to obtain the following vector:
b= [ 7 8 9 7 8 9; 17 18 19 17 18 19; 27 28 29 27 28 29; 37 38 39 37 38 39 ...]
I am replicating the vector and then summing 10 for each line (for n lines). I would like to do this without using loop iterations. How can I do it? Thank you so much.
0 个评论
采纳的回答
更多回答(2 个)
Image Analyst
2015-9-19
Try this:
a=[7,8,9,7,8,9]
n = 8; % Whatever you want.
firstColumn = (0:10:10*(n-1))'
b = repmat(firstColumn, [1, length(a)]) + repmat(a, [n, 1])
0 个评论
另请参阅
类别
在 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!