필터 지우기
필터 지우기

Add n+1 element to a vector

조회 수: 1 (최근 30일)
steve Brian
steve Brian 2020년 4월 10일
댓글: Peng Li 2020년 4월 10일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by