Clear Filters
Clear Filters

Vector of n elements

17 views (last 30 days)
Maciej Kupras
Maciej Kupras on 17 May 2020
Commented: Maciej Kupras on 5 Jun 2020
Hey!
How can I create such a vector:
[1,1+2,1+2+3, ... ,1+2+3+...+n]
without a loop?

Accepted Answer

Star Strider
Star Strider on 17 May 2020
Try this:
v = 1:n;
vs = cumsum(v)
.
  2 Comments
Maciej Kupras
Maciej Kupras on 17 May 2020
Thank you very much :)
Star Strider
Star Strider on 17 May 2020
As always, my pleasure!

Sign in to comment.

More Answers (2)

David Hill
David Hill on 17 May 2020
a=1:n;
A=a.*(a+1)/2;

Marcel Król
Marcel Król on 5 Jun 2020
cześć
Jak mogę stworzyć wektor kolumnowy n elementowy? Proszę o pomoc
  1 Comment
Maciej Kupras
Maciej Kupras on 5 Jun 2020
Możesz stworzyć macierz jednokolumnową.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!