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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2020년 4월 10일

댓글:

2020년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by