What is the shortest way to get the last N elements of an array?

I wrote

array = linspace(0, 1);
sliceSize = 10;
sliceBegin = 1 + length(array) - sliceSize;
slice = array(sliceBegin: length(array));

which is too verbose. How to make it shorter?

+3
source share
1 answer
a = rand(100,1);    %# vector
a(end-5+1:end)      %# last five elements
+17
source

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


All Articles