How can I return the last value of a vector?

303 vues (au cours des 30 derniers jours)
Thor
Thor le 18 Avr 2013
Commenté : Stephen Gerdts le 17 Fév 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!

Réponse acceptée

Kye Taylor
Kye Taylor le 18 Avr 2013
Modifié(e) : Kye Taylor le 18 Avr 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, ...

Plus de réponses (1)

Ehsan R
Ehsan R le 18 Avr 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

Catégories

En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by