Matlab, an index from the starting location to the last index

Say you have an array of data with an unknown length. Is there a shorter method for getting the elements that make up the initial index to the end than

subdata = data(2:length(data)) 
+4
source share
1 answer

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

This can also be done using matrices, i.e. data(2:end,5:end) . In addition, 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 using functions / loops / switches at the end.

+12
source

Source: https://habr.com/ru/post/1307229/


All Articles