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 ExchangeData Types についてさらに検索

タグ

質問済み:

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