How can I return the last value of a vector?

T
Tanner · Nov 19, 2020 · 2.3K views
Question
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!
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 13, 2026

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, ...

Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!