フィルターのクリア

How to repeat a vector number of times with a certain value added to each row

1 回表示 (過去 30 日間)
bassant tolba
bassant tolba 2023 年 5 月 15 日
回答済み: Dyuman Joshi 2023 年 5 月 15 日
I have a vector [1 2 3 4 5]
I would like to repeat this vector 3 times each time has an added value of 4
to get output like this
[1 2 3 4 5;
5 6 7 8 9;
9 10 11 12 13;]
This is a simple example, I would apply this on vector with 1x50 value

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2023 年 5 月 15 日
vec = 1:5;
rep = 3;
val = 4;
out = vec + val*(0:rep-1)'
out = 3×5
1 2 3 4 5 5 6 7 8 9 9 10 11 12 13

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by