Pre allocation in matlab

조회 수: 9 (최근 30일)
Seoyoung Cho
Seoyoung Cho 2020년 2월 10일
댓글: Walter Roberson 2020년 2월 10일
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에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by