views:

48

answers:

1

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))
+7  A: 

You can use end notation to indicate the last element. data(2:end) returns a vector containing elements in the vector data from element 2 to the last element. Or if data is a character array, it returns the second character all the way to the last character.

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, end serves a different purpose from its use at the end of functions/loops/switches.

JS Ng
Perfect, thank you!
ccook