row that increases more every element

Hello,
I was wondering how I would make an array that increases more every element
for example:
given lets say n=randi([10 20], 1);
how would i have vect1 = 9, 16, 25, 36, ... n: so bascially increasing by +2 every element starting at 9

3 件のコメント

KSSV
KSSV 2022 年 5 月 20 日
Your limit of numbers is [10,20] how you expect 25, 36 .. ?
Walter Roberson
Walter Roberson 2022 年 5 月 20 日
Your example increases by 9 each time, not by 2?
Are you wanting to start with the fixed value 9 and use the random number to determine the number of terms??
RozuSolo
RozuSolo 2022 年 5 月 20 日
it increases 7 then 9 then 11 then 13 ect.. so starting at 9 increases by 7 + 2* (what ever element you are on - 1)

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

 採用された回答

RozuSolo
RozuSolo 2022 年 5 月 20 日

1 投票

nvm I got it.. It's just two vectors multiplied to each other [3, n] .* [3, n] so each element is 3x3 4x4 5x5 6x6 ect...

その他の回答 (1 件)

DGM
DGM 2022 年 5 月 20 日

0 投票

Here's my guess:
A = randi([10 20], 1,10)
A = 1×10
11 18 15 16 19 13 12 12 12 15
B = cumsum(A) % cumulative sum of A
B = 1×10
11 29 44 60 79 92 104 116 128 143

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2022 年 5 月 20 日

回答済み:

2022 年 5 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by