Pre allocation in matlab
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Seoyoung Cho
am 10 Feb. 2020
Kommentiert: Walter Roberson
am 10 Feb. 2020
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!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 10 Feb. 2020
length(v)
zeros(size(v))
3 Kommentare
Walter Roberson
am 10 Feb. 2020
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.)
Weitere Antworten (1)
fred ssemwogerere
am 10 Feb. 2020
leng=length(v); % length of a vector
pA=zeros(1,leng); % pre-allocation with zeros
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!