查看单个帖子
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 获取数组的最后N个项的最短方法是什么?

我写

array = linspace(0, 1); sliceSize = 10; sliceBegin = 1 + length(array) - sliceSize; slice = array(sliceBegin: length(array)); 太冗长了。如何使其更短?



回答:

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

更多&回答...
poster 当前离线   回复时引用此帖