Replicating a vector while summing an increasing value

3 ビュー (過去 30 日間)
Jose Luis
Jose Luis 2015 年 9 月 19 日
コメント済み: Star Strider 2015 年 9 月 19 日
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.

採用された回答

Star Strider
Star Strider 2015 年 9 月 19 日
This works:
a = [ 7 8 9 7 8 9];
n = 4;
b = bsxfun(@plus, a, [0:10:n*10]');
  2 件のコメント
Jose Luis
Jose Luis 2015 年 9 月 19 日
Thank you, all the answers works
Star Strider
Star Strider 2015 年 9 月 19 日
My pleasure.

サインインしてコメントする。

その他の回答 (2 件)

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

Image Analyst
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])

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by