Add n+1 element to a vector

4 次查看(过去 30 天)
I have a vector of the format:
x = [X1 X2 … Xn]
I want to add an element to the end, X(n+1). How do I do that?
ex: x = [ 1 4 2 8]
newX = [ 1 4 2 8 9]

采纳的回答

Peng Li
Peng Li 2020-4-10
If your X is a row vector, using newX = [X, aNewElement];
If your X is a column vector, using newX = [X; aNewElement];
  2 个评论
steve Brian
steve Brian 2020-4-10
but, i want aNewElement to be, n+1
like [ 1 4 2 8 8+1]
Peng Li
Peng Li 2020-4-10
newX = [X, X(end)+1];

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Automated Driving Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by