How can I return the last value of a vector?

144 Ansichten (letzte 30 Tage)
Thor
Thor am 18 Apr. 2013
Kommentiert: Stephen Gerdts am 17 Feb. 2016
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!

Akzeptierte Antwort

Kye Taylor
Kye Taylor am 18 Apr. 2013
Bearbeitet: Kye Taylor am 18 Apr. 2013
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, ...

Weitere Antworten (1)

Ehsan R
Ehsan R am 18 Apr. 2013
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

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by