Say you have an array, data, of unknown length. Is there a shorter method to get elements form a starting index to the end than
subdata = data(2:length(data))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
endnotation to indicate the last element.data(2:end)returns a vector containing elements in the vectordatafrom element 2 to the last element. Or ifdatais a character array, it returns the second character all the way to the last character. Anddata(end)returns the last element.This can be done with matrices too, i.e.
data(2:end,5:end). Additionally you can use it as an operand, i.e.data(2:end-1),data(2:end/2).In this context,
endserves a different purpose from its use at the end of functions/loops/switches.