How can I return the last value of a vector?

Illustration
Tanner - 2020-11-19T11:31:08+00:00
Question: How can I return the last value of a vector?

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 answered . 2025-11-20

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


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!