append elements to a vector

35 次查看(过去 30 天)
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?

采纳的回答

Matt Fig
Matt Fig 2012-11-8
编辑:Matt Fig 2012-11-8
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 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by