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]

 Respuesta aceptada

Peng Li
Peng Li el 10 de Abr. de 2020

0 votos

If your X is a row vector, using newX = [X, aNewElement];
If your X is a column vector, using newX = [X; aNewElement];

2 comentarios

steve Brian
steve Brian el 10 de Abr. de 2020
but, i want aNewElement to be, n+1
like [ 1 4 2 8 8+1]
Peng Li
Peng Li el 10 de Abr. de 2020
newX = [X, X(end)+1];

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Types en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Abr. de 2020

Comentada:

el 10 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by