开发者

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

I wrote

array = linspa开发者_运维知识库ce(0, 1);
sliceSize = 10;
sliceBegin = 1 + length(array) - sliceSize;
slice = array(sliceBegin: length(array));

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


a = rand(100,1);    %# vector
a(end-5+1:end)      %# last five elements
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜