How can I return the last value of a vector?

309 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

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

Più risposte (1)

Ehsan R
Ehsan R il 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

Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by