查看单个帖子
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在MATLAB中提取N个最小点和N个最大点(忽略数组中的重复点)?

我有一些类似的点

x=[1 1 1 2 2 4 4 5 6 ......7 8 8 9 9] 我想有一个包含3个元素的数组,该元素的最小元素数和3个元素的最大元素数(忽略相同的元素)

上面的预期结果将是

ans=[1 2 4 7 8 9]

回答:

您可以使用UNIQUE函数执行此操作:

uniqueValues = unique(x); %# Get the unique values of x minmaxValues = uniqueValues([1:3 end-2:end]); %# Get the 3 smallest and largest

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