Pre allocation in matlab

1 次查看(过去 30 天)
v = [0 8 1 2 6 4 8]
How do I determine length of the vector?
Also, how do I pre-allocate the descending vector with all zeros?
Thank you!

采纳的回答

Walter Roberson
Walter Roberson 2020-2-10
length(v)
zeros(size(v))
  3 个评论
Seoyoung Cho
Seoyoung Cho 2020-2-10
do you know how to do pre-allocate the ascending vector with all zeros?
Walter Roberson
Walter Roberson 2020-2-10
zeros(size(v)) works no matter whether you are planning to put ascending or descending variables; it also works even if you are planning to put complex numbers in (I mention those because complex numbers cannot generally be ordered into ascending or descending.)

请先登录,再进行评论。

更多回答(1 个)

fred  ssemwogerere
fred ssemwogerere 2020-2-10
leng=length(v); % length of a vector
pA=zeros(1,leng); % pre-allocation with zeros

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by