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

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!