Vector of n elements

17 次查看(过去 30 天)
Hey!
How can I create such a vector:
[1,1+2,1+2+3, ... ,1+2+3+...+n]
without a loop?

采纳的回答

Star Strider
Star Strider 2020-5-17
Try this:
v = 1:n;
vs = cumsum(v)
.

更多回答(2 个)

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

Marcel Król
Marcel Król 2020-6-5
cześć
Jak mogę stworzyć wektor kolumnowy n elementowy? Proszę o pomoc

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by