How can I return the last value of a vector?

303 visualizaciones (últimos 30 días)
Thor
Thor el 18 de Abr. de 2013
Comentada: Stephen Gerdts el 17 de Feb. de 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!

Respuesta aceptada

Kye Taylor
Kye Taylor el 18 de Abr. de 2013
Editada: Kye Taylor el 18 de Abr. de 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, ...

Más respuestas (1)

Ehsan R
Ehsan R el 18 de Abr. de 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

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by