Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab, index from starting location to last index

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))
like image 394
ccook Avatar asked Apr 17 '10 17:04

ccook


1 Answers

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

like image 69
JS Ng Avatar answered Sep 19 '22 13:09

JS Ng