How can I return the last value of a vector?

301 ビュー (過去 30 日間)
Thor
Thor 2013 年 4 月 18 日
コメント済み: Stephen Gerdts 2016 年 2 月 17 日
Dear all,
is there a command in Matlab, which returns the last value of a vector? In R is this command called "tail". For example: X = [1, 2, 3, 4] and I need a command which returns the last value. Like tail(X) = 4. Thank you in advance!

採用された回答

Kye Taylor
Kye Taylor 2013 年 4 月 18 日
編集済み: Kye Taylor 2013 年 4 月 18 日
Try
X(end)
In general, if X is a m-by-n-by-p-by...
You can use
X(end,end,end,...)
to access element in last row, last column, last sheet, ...

その他の回答 (1 件)

Ehsan R
Ehsan R 2013 年 4 月 18 日
X = [1, 2, 3, 4]
X(end)
ans>>4 ****************************************
X=[1 2 3 4 5 6;7 8 9 10 11 12;13 14 15 16 17 18];
X= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
A(3,6:end)
ans>>18

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by