append elements to a vector
35 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
At the beginning of my simulation I create an empty vector
vector = []
During the simulation I insert some elements into this vector. The elements could be repeated. How can I append elements to this vector without deleting the existing elements?
0 Commenti
Risposta accettata
Matt Fig
il 8 Nov 2012
Modificato: Matt Fig
il 8 Nov 2012
The usual way to do it is something like this.
v = [];
for ii = 1:3
v = [v ii:4];
end
v % Show v
Note that it is usually better to avoid growing an array in a loop if possible. But one would have to see the code to know if it should be avoided.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!