MATLAB Answers

append elements to a vector

534 ビュー (過去 30 日間)
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 11 月 8 日
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 件のコメント

Sign in to comment.

採用された回答

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 件のコメント

Sign in to comment.

その他の回答 (0 件)

タグ


Translated by