MATLAB: Taking the last value of a matrix or vector

last term of a vector with n rows

Hi. How can I take a last term of a vector – since my vector dimensions change -, and plug it in somewhere else in my code without keep changing the code?
for example right now I do v(6) to get the 6th term. How can I do it for nth term…. Thanks

Best Answer

v(end)
or
v(length(v))