Add n+1 element to a vector

1 view (last 30 days)
steve Brian
steve Brian on 10 Apr 2020
Commented: Peng Li on 10 Apr 2020
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]

Accepted Answer

Peng Li
Peng Li on 10 Apr 2020
If your X is a row vector, using newX = [X, aNewElement];
If your X is a column vector, using newX = [X; aNewElement];
  2 Comments
Peng Li
Peng Li on 10 Apr 2020
newX = [X, X(end)+1];

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by