Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the shortest way of getting the last N items of an array?

Tags:

arrays

matlab

I wrote

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

that's too verbose. How to make it shorter?

like image 249
Jader Dias Avatar asked Nov 30 '22 05:11

Jader Dias


1 Answers

a = rand(100,1);    %# vector
a(end-5+1:end)      %# last five elements
like image 60
Amro Avatar answered Dec 01 '22 20:12

Amro