Replicating a vector while summing an increasing value

11 Ansichten (letzte 30 Tage)
Jose Luis
Jose Luis am 19 Sep. 2015
Kommentiert: Star Strider am 19 Sep. 2015
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.

Akzeptierte Antwort

Star Strider
Star Strider am 19 Sep. 2015
This works:
a = [ 7 8 9 7 8 9];
n = 4;
b = bsxfun(@plus, a, [0:10:n*10]');

Weitere Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 19 Sep. 2015
a = [ 7 8 9 7 8 9];
bsxfun(@plus,a,10*[1:5]')

Image Analyst
Image Analyst am 19 Sep. 2015
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])

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by